summaryrefslogtreecommitdiff
path: root/lua_benchmark/tests/Lua-Benchmarks/sieve.lua
diff options
context:
space:
mode:
authorMatthew Sotoudeh <matthew@masot.net>2024-05-17 15:57:30 -0700
committerMatthew Sotoudeh <matthew@masot.net>2024-05-17 15:57:30 -0700
commitd068f0b3c11348a50c18af1ee3b0d2e5f38c4faf (patch)
treedb777acca2336f8c279e9f09346f02de7ddaa0e9 /lua_benchmark/tests/Lua-Benchmarks/sieve.lua
parent221b05e7a86faa38036429d5fbfc8b0779eb5382 (diff)
lua benchmarks
Diffstat (limited to 'lua_benchmark/tests/Lua-Benchmarks/sieve.lua')
-rw-r--r--lua_benchmark/tests/Lua-Benchmarks/sieve.lua33
1 files changed, 33 insertions, 0 deletions
diff --git a/lua_benchmark/tests/Lua-Benchmarks/sieve.lua b/lua_benchmark/tests/Lua-Benchmarks/sieve.lua
new file mode 100644
index 0000000..e2c1487
--- /dev/null
+++ b/lua_benchmark/tests/Lua-Benchmarks/sieve.lua
@@ -0,0 +1,33 @@
+-- $Id: sieve.lua,v 1.9 2001/05/06 04:37:45 doug Exp $
+-- http://www.bagley.org/~doug/shootout/
+--
+-- Roberto Ierusalimschy pointed out the for loop is much
+-- faster for our purposes here than using a while loop.
+
+local count = 0
+
+function main(num, lim)
+ local flags = {}
+ for num=num,1,-1 do
+ count = 0
+ for i=1,lim do
+ flags[i] = 1
+ end
+ for i=2,lim do
+ if flags[i] == 1 then
+ k = 0
+ for k=i+i, lim, i do
+ flags[k] = 0
+ end
+ count = count + 1
+ end
+ end
+ end
+end
+
+NUM = tonumber((arg and arg[1])) or 100
+lim = (arg and arg[2]) or 8192
+print(NUM,lim)
+count = 0
+main(NUM, lim)
+print("Count: ", count)
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback