Discussion:
Dynamic array benchmark
Fredrik Widlund
2014-09-24 14:13:10 UTC
Permalink
http://lonewolfer.wordpress.com/2014/09/24/benchmarking-dynamic-array-implementations/

Microbenchmark of Java/C++/C/LuaJIT arrays
Alex
2014-09-24 14:31:06 UTC
Permalink
Please post the code you've used to benchmark in all of your languages.
I've seen 'benchmarks' in Lua that don't even use local variables.

(Also, why did you use Java's depreciated Vector class instead of something
like ArrayList?)
Post by Fredrik Widlund
http://lonewolfer.wordpress.com/2014/09/24/benchmarking-dynamic-array-implementations/
Microbenchmark of Java/C++/C/LuaJIT arrays
--
Sincerely,
Alex Parrill
Alex
2014-09-24 14:31:40 UTC
Permalink
Nevermind about Vector vs ArrayList, just read the footer.
Post by Alex
Please post the code you've used to benchmark in all of your languages.
I've seen 'benchmarks' in Lua that don't even use local variables.
(Also, why did you use Java's depreciated Vector class instead of
something like ArrayList?)
On Wed, Sep 24, 2014 at 10:13 AM, Fredrik Widlund <
Post by Fredrik Widlund
http://lonewolfer.wordpress.com/2014/09/24/benchmarking-dynamic-array-implementations/
Microbenchmark of Java/C++/C/LuaJIT arrays
--
Sincerely,
Alex Parrill
--
Sincerely,
Alex Parrill
Fredrik Widlund
2014-09-24 14:45:45 UTC
Permalink
Add source ref. I'll answer comments on the post rather than here if
possible.

Kind regards,
Fredrik
Post by Alex
Please post the code you've used to benchmark in all of your languages.
I've seen 'benchmarks' in Lua that don't even use local variables.
(Also, why did you use Java's depreciated Vector class instead of
something like ArrayList?)
On Wed, Sep 24, 2014 at 10:13 AM, Fredrik Widlund <
Post by Fredrik Widlund
http://lonewolfer.wordpress.com/2014/09/24/benchmarking-dynamic-array-implementations/
Microbenchmark of Java/C++/C/LuaJIT arrays
--
Sincerely,
Alex Parrill
Mike Pall
2014-09-24 15:08:53 UTC
Permalink
Post by Fredrik Widlund
Add source ref. I'll answer comments on the post rather than here if
possible.
Sorry, no. You're posting here, you get the answers here.

table.insert is well known not to be suitable for any situation
where speed would be a concern. It's 50x faster to use a plain
counter variable, 100x faster to use a for loop variable as an
index and 250x faster to use an FFI array of integers.

--Mike

Raymond W. Ko
2014-09-24 15:02:07 UTC
Permalink
Although I don't have socket installed for socket for LuaJIT installed,
and only tested this with Lua, this should result in a performance
improvement.

table.insert(t, v) uses #table which are both worst case log(n)
operations. This should be closer to amortized O(1) performance.

--- vector_grow_lua.lua 2014-09-24 10:58:14.787795863 -0400
+++ vector_grow_lua2.lua 2014-09-24 10:57:30.453351392 -0400
@@ -6,13 +6,15 @@
local n = tonumber(arg[1])
local m = {}
local v = {}
+ local next_v_index = 1
local t

t = socket.gettime()
m[0] = 0
for i = 0, n - 1, n / 100 do
for j = 0, (n / 100) - 1 do
- table.insert(v, j)
+ v[next_v_index] = j
+ next_v_index = next_v_index + 1
end
m[i / (n / 100) + 1] = socket.gettime() - t;
end
Post by Alex
Please post the code you've used to benchmark in all of your
languages. I've seen 'benchmarks' in Lua that don't even use local
variables.
(Also, why did you use Java's depreciated Vector class instead of
something like ArrayList?)
On Wed, Sep 24, 2014 at 10:13 AM, Fredrik Widlund
http://lonewolfer.wordpress.com/2014/09/24/benchmarking-dynamic-array-implementations/
Microbenchmark of Java/C++/C/LuaJIT arrays
--
Sincerely,
Alex Parrill
Continue reading on narkive:
Loading...