Skip to content

Commit 9e4c0a7

Browse files
EntityFXEntityFX
authored andcommitted
Fic clock choose, jit detect
1 parent 6490d27 commit 9e4c0a7

4 files changed

Lines changed: 71 additions & 17 deletions

File tree

src/lua/dhrystone/dhrystone.lua

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,10 @@ function Dhrystone2:bench(loops)
4545
self.output:writeLine("")
4646
self.output:writeLine("Dhrystone Benchmark, Version 2.1 (Language: Lua)")
4747
self.output:writeLine("")
48-
self.output:writeLine("Optimization %s", "Optimised")
48+
49+
local optimization = getVersion() .. ((jit and jit.status() == true) and " Optimised" or " Not optimised")
50+
51+
self.output:writeLine("Optimization: %s", optimization)
4952

5053
local result = self:Proc0(loops)
5154

src/lua/main.lua

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,13 @@ if _ENV then
2525
unpack = table.unpack
2626
end
2727

28+
if #arg > 0 then
29+
if arg[1] == "1" then
30+
useTimeForClock = true
31+
end
32+
end
33+
print("useTimeForClock=", useTimeForClock)
34+
2835
function writeResult(writer, benchResult)
2936
writer:writeTitle("%-30s", benchResult.benchmarkName)
3037
writer:writeValue("%15d ms", benchResult.elapsed)
@@ -40,18 +47,18 @@ local writer = Writer("Output.log")
4047
BenchmarkBase.IterrationsRatio = 0.1
4148

4249
benchmarks = {
43-
-- ArithemticsBenchmark(writer, true),
44-
-- MathBenchmark(writer, true),
45-
-- CallBenchmark(writer, true),
46-
-- IfElseBenchmark(writer, true),
47-
-- StringManipulation(writer, true),
48-
-- MemoryBenchmark(writer, true),
49-
-- RandomMemoryBenchmark(writer, true),
50-
-- Scimark2Benchmark(writer, true),
50+
ArithemticsBenchmark(writer, true),
51+
MathBenchmark(writer, true),
52+
CallBenchmark(writer, true),
53+
IfElseBenchmark(writer, true),
54+
StringManipulation(writer, true),
55+
MemoryBenchmark(writer, true),
56+
RandomMemoryBenchmark(writer, true),
57+
Scimark2Benchmark(writer, true),
5158
DhrystoneBenchmark(writer, true),
52-
-- WhetstoneBenchmark(writer, true),
53-
-- LinpackBenchmark(writer, true),
54-
-- HashBenchmark(writer, true)
59+
WhetstoneBenchmark(writer, true),
60+
LinpackBenchmark(writer, true),
61+
HashBenchmark(writer, true)
5562
}
5663

5764
writer:writeHeader("Warmup")
@@ -89,6 +96,7 @@ writer:writeLine()
8996

9097
local os, arch = getOS()
9198
local osVersion = os .. ' ' .. arch
99+
local runtime = getVersion()
92100

93101
local headerCommon = "Operating System,Runtime,Threads Count,Memory Used"
94102
local headerTotals = ",Total Points,Total Time (ms)"
@@ -101,7 +109,7 @@ for i,benchmark in ipairs(benchmarks) do
101109
end
102110
writer:writeTitle(headerTotals)
103111
writer:writeLine()
104-
writer:writeTitle("%s,%s,%d,%d", osVersion, _VERSION, 1, 0)
112+
writer:writeTitle("%s,%s,%d,%d", osVersion, runtime, 1, 0)
105113
for i,point in ipairs(points) do
106114
writer:writeTitle(",%.2f", point)
107115
end
@@ -116,7 +124,7 @@ for i,benchmark in ipairs(benchmarks) do
116124
end
117125
writer:writeTitle(headerTotals)
118126
writer:writeLine()
119-
writer:writeTitle("%s,%s,%d,%d", osVersion, _VERSION, 1, 0)
127+
writer:writeTitle("%s,%s,%d,%d", osVersion, runtime, 1, 0)
120128
for i,result in ipairs(results) do
121129
writer:writeTitle(",%.2f", result)
122130
end

src/lua/utils.lua

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
useTimeForClock = false
2+
13
function class(base, init)
24
local c = {} -- a new class instance
35
if not init and type(base) == 'function' then
@@ -106,12 +108,26 @@ function sum(x)
106108
end
107109

108110
function clock()
109-
local clk = os.clock() * 1000
111+
local clk = 0
112+
if (useTimeForClock) then
113+
clk = os.time() * 1000
114+
else
115+
clk = os.clock() * 1000
116+
end
117+
110118
return clk
111119
end
112120

113121
function clockSeconds()
114-
return clock() / 1000.0
122+
local clk = 0
123+
124+
if (useTimeForClock) then
125+
clk = os.time()
126+
else
127+
clk = os.clock()
128+
end
129+
130+
return clk
115131
end
116132

117133
-- Calculates the arithmetic mean of a set of values
@@ -204,4 +220,29 @@ function getOS()
204220
end
205221
end
206222
return os_name, arch_name
223+
end
224+
225+
function getVersion()
226+
if jit then
227+
if jit.version then
228+
return jit.version
229+
else
230+
return _VERSION .. " JIT"
231+
end
232+
else
233+
return _VERSION
234+
end
235+
end
236+
237+
function dump(o)
238+
if type(o) == 'table' then
239+
local s = '{ '
240+
for k,v in pairs(o) do
241+
if type(k) ~= 'number' then k = '"'..k..'"' end
242+
s = s .. '['..k..'] = ' .. dump(v) .. ','
243+
end
244+
return s .. '} '
245+
else
246+
return tostring(o)
247+
end
207248
end

src/lua/whetstone/whetstone.lua

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,20 @@ function Whetstone:bench(getinput)
2121

2222
local count = 10
2323
local calibrate = 1
24-
local xtra = 1
24+
local xtra = 125
2525
local endit = 0
2626
local section = 0
2727
local x100 = 100
2828
local duration = 100
2929
local general = {}
3030
self:writeLine("%s Precision Lua Whetstone Benchmark\n", "Double")
31+
3132
if not getinput then
3233
self:writeLine("No run time input data\n")
3334
else
3435
self:writeLine("With run time input data\n")
3536
end
37+
3638
self:writeLine("Calibrate")
3739
repeat
3840
self.timeUsed = 0.0

0 commit comments

Comments
 (0)