majqq

Object vs array table structure

Recommended Posts

Posted (edited)

Hey, i would like to know which is faster, and better to use. Or there's no any difference in performance between them?

For example in render, or any different usage. As far i understand from reading IIYAMA's posts, for render it's better to use array structure?

 

Edited by majqq

Share this post


Link to post

Can you explain in more detail what you mean by object vs array? Are you referring to JSON data format?

If you're referring to element (object) data storage, versus standard storage in Lua tables, then Lua tables are always going to perform better. However, some more understanding of what you mean / what you're trying to do would help explain it :) 

Share this post


Link to post
1 minute ago, LopSided said:

Can you explain in more detail what you mean by object vs array? Are you referring to JSON data format?

If you're referring to element (object) data storage, versus standard storage in Lua tables, then Lua tables are always going to perform better. However, some more understanding of what you mean / what you're trying to do would help explain it :) 

Lua tables, check first post, i've edited it.

Share this post


Link to post
Posted (edited)
On 08/07/2019 at 14:15, LopSided said:

Can you explain in more detail what you mean by object vs array? Are you referring to JSON data format?

JS object format types, which is more or less the same as JSON. Just it is not a string but an entity.

Which is a way for myself to separate array structured tables from tables with mixed keys. Might be good or bad practice, I myself to be honest do not know.

 

@majqq

If you need confirmation, then the best way is to test it yourself.

 

 

local newTable_array = {}
local newTable_object = {}
local loops = 1000

for i = 1, 1000 do
	newTable_array[i] = true
	newTable_object[i .. ""] = true
end

 

do
	local timeNow = getTickCount ()
	for _ = 1, loops do
		for i=1, #newTable_array do
			local value = newTable_array[i]
		end
	end
	outputChatBox(getTickCount () - timeNow)
end

 

do
	local timeNow = getTickCount ()
	for _ = 1, loops do
		for key, value in pairs(newTable_array) do
			
		end
	end
	outputChatBox(getTickCount () - timeNow)
end

 

do
	local timeNow = getTickCount ()
	for _ = 1, loops do
		for key, value in ipairs(newTable_array) do
			
		end
	end
	outputChatBox(getTickCount () - timeNow)
end

 

do
	local timeNow = getTickCount ()
	for _ = 1, loops do
		for key, value in pairs(newTable_object) do
			
		end
	end
	outputChatBox(getTickCount () - timeNow)
end

 

 

 

 

 

 

 

Edited by IIYAMA
  • Like 1

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.