summaryrefslogtreecommitdiff
path: root/Data/DefaultContent/Libraries/LiteJson/bench/util/bench.lua
diff options
context:
space:
mode:
authorchai <chaifix@163.com>2021-11-15 11:54:17 +0800
committerchai <chaifix@163.com>2021-11-15 11:54:17 +0800
commit30f2f46474bf4eda5f10d4c64a07cde01d469f66 (patch)
tree6ff2ed3262037b3c9bae2d2b9059a1d65773f31c /Data/DefaultContent/Libraries/LiteJson/bench/util/bench.lua
parent4c36bed53fe63ae6056730b3ecad2573f03d88f8 (diff)
*rename DefaultContent -> BuiltIn
Diffstat (limited to 'Data/DefaultContent/Libraries/LiteJson/bench/util/bench.lua')
-rw-r--r--Data/DefaultContent/Libraries/LiteJson/bench/util/bench.lua62
1 files changed, 0 insertions, 62 deletions
diff --git a/Data/DefaultContent/Libraries/LiteJson/bench/util/bench.lua b/Data/DefaultContent/Libraries/LiteJson/bench/util/bench.lua
deleted file mode 100644
index 9f02738..0000000
--- a/Data/DefaultContent/Libraries/LiteJson/bench/util/bench.lua
+++ /dev/null
@@ -1,62 +0,0 @@
-local bench = {}
-
-local unpack = unpack or table.unpack
-local fmt = string.format
-
-
-function bench.run(name, count, func)
- -- Run bench
- local res = {}
- for i = 1, count do
- local start_time = os.clock()
- func()
- table.insert(res, (os.clock() - start_time))
- end
- -- Calculate average
- local avg = 0
- for i, v in ipairs(res) do
- avg = avg + v
- end
- avg = avg / #res
- -- Build and return result table
- return {
- name = name,
- avg = avg,
- min = math.min(unpack(res)),
- max = math.max(unpack(res)),
- all = res,
- }
-end
-
-
-function bench.get_cpu_name()
- local fp = io.open("/proc/cpuinfo", "rb")
- if not fp then
- return "unknown"
- end
- local text = fp:read("*a")
- return text:match("model name%s*:%s*(.-)\n")
-end
-
-
-function bench.print_system_info()
- print( fmt("Lua version : %s", jit and jit.version or _VERSION) )
- print( fmt("CPU name : %s", bench.get_cpu_name()) )
-end
-
-
-function bench.print_results(results)
- -- Find best average
- local best = math.huge
- for i, v in ipairs(results) do
- best = math.min(best, v.avg)
- end
- -- Print results
- for i, v in ipairs(results) do
- print( fmt("%-13s : %.03gs [x%1.3g] (min: %.03gs, max %.03gs)",
- v.name, v.avg, v.avg / best, v.min, v.max) )
- end
-end
-
-
-return bench