Skip to content

Instantly share code, notes, and snippets.

@jpoon
Last active May 11, 2020 23:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jpoon/341fd127dc91da4e6167a216fe7554cd to your computer and use it in GitHub Desktop.
Save jpoon/341fd127dc91da4e6167a216fe7554cd to your computer and use it in GitHub Desktop.
#!/usr/bin/env sysbench
-- you can run this script like this:
-- -- $ ./prime-test.lu0a --cpu-max-prime=20000 --threads=8 --report-interval=10 --time=999999999 run
sysbench.cmdline.options = {
-- the default values for built-in options are currently ignored, see
-- https://github.com/akopytov/sysbench/issues/151
["test"] = {"test", "cpu"},
["cpu-max-prime"] = {"CPU maximum prime", 20000},
["threads"] = {"Number of threads", 1},
["report-interval"] = {"Report interval", 1}
}
function event()
local n = 0
for c = 3, sysbench.opt.cpu_max_prime do
local t = math.sqrt(c)
local isprime = true
for l = 2, t do
if c % l == 0 then
isprime = false
break
end
end
if isprime then
n = n + 1
end
end
end
function sysbench.hooks.report_intermediate(stat)
local curTime = os.time()
local seconds = stat.time_interval
print(string.format("%s, %4.2f",
os.date("%H:%M:%S"),
stat.events / seconds))
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment