From WikiChip
Difference between revisions of "Module:benchmarks"

(Created page with "local benchmark = {} local origArgs function has_arg(name) -- The argument can exist and be empty or not exist at all return string.len(origArgs[name] or '') > 0 end funct...")
(No difference)

Revision as of 23:29, 4 July 2017

Documentation for this module may be created at Module:benchmarks/doc

local benchmark = {}
local origArgs

function has_arg(name)
	-- The argument can exist and be empty or not exist at all
	return string.len(origArgs[name] or '') > 0
end

function arg(name)
	return origArgs[name]
end

function single_entry(box, argn)
	if has_arg(argn) then
		box:tag('div'):attr('min-width: 250px; display: inline-block;'):wikitext("'''" .. argn .. ":''' " .. arg(argn))
	end
end

function benchmark.benchmark(frame)

    if frame == mw.getCurrentFrame() then
        origArgs = frame:getParent().args
    else
        origArgs = frame
    end

    local benchmarkbox = mw.html.create('div')

    benchmarkbox
        :attr('style', 'background:#f9f9f9; margin: 10px 2px 10px 2px; padding: 5px; border: 1px solid #a7d7f9; display: inline-block;')
        
    if not has_arg('type') then
    	return "* ERROR: '''WRONG <code>type</code> parameter!'''"	
	end
	
	if arg('type') == 'spec' then
		return 	benchmark.spec(benchmarkbox)
	end
   
   return benchmarkbox     
end


function benchmark.spec(box)
    box:tag('span'):attr('style', 'float: right;'):wikitext("'''Tested:''' " ..
    	'[' .. arg('test_link') .. ' ' .. arg('test_timestamp') .. ']')
    
    box:tag('div'):attr('style', 'vertical-align: middle;')
    			:wikitext("[[File:benchmarks.svg|64px|link=|left]] '''Vendor:''' " ..
    				arg('vendor') .. "<br>'''System:''' " .. arg('system') .. "</div>")
    			
	b = box:tag('div'):attr('style', 'border: 1px solid black; padding: 10px; margin: 0; width: 100%;')
   
   single_entry(b, 'SPECspeed2017_int_base')
   single_entry(b, 'SPECspeed2017_int_peak')
   single_entry(b, 'SPECspeed2017_fp_base')
   single_entry(b, 'SPECspeed2017_fp_peak')
   single_entry(b, 'SPECrate2017_int_base')
   single_entry(b, 'SPECrate2017_int_peak')
   single_entry(b, 'SPECrate2017_fp_base')
   single_entry(b, 'SPECrate2017_fp_peak')
   
   return box
end