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 AlexPlease 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