generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripting Helpers
Home Search
 

Re: Pairs or ipairs

Previous Thread :: Next Thread 
ProfitMargin is not online. ProfitMargin
Joined: 01 Aug 2013
Total Posts: 285
26 Aug 2013 08:31 PM
I forgot which one gets all of the table.
Report Abuse
ScrewDeath is not online. ScrewDeath
Joined: 03 Jun 2012
Total Posts: 2700
26 Aug 2013 08:33 PM
pairs.

ipairs only gets the indices that are numbers
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
26 Aug 2013 09:25 PM
Pairs is faster
Report Abuse
ProfitMargin is not online. ProfitMargin
Joined: 01 Aug 2013
Total Posts: 285
26 Aug 2013 09:26 PM
:o How would you know?
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
26 Aug 2013 09:27 PM
function test(qq) for i, v in pairs(Game.Workspace:GetChildren()) do print(qq) end end
function test2(qq) for i, v in ipairs(Game.Workspace:GetChildren()) do print(qq) end end

Delay(0, test)
Delay(0, test2)
Report Abuse
ProfitMargin is not online. ProfitMargin
Joined: 01 Aug 2013
Total Posts: 285
26 Aug 2013 09:29 PM
Man you are such a guud scripter. HOw did you learn this stuff cnt? And do you wrte on the wiki? Oh and thanks.
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
26 Aug 2013 09:30 PM
I think all the wiki topics are taken lol
Report Abuse
shonclub is not online. shonclub
Joined: 05 Sep 2009
Total Posts: 1331
26 Aug 2013 09:30 PM
Cnt hacked Kolh's brain.
Report Abuse
ProfitMargin is not online. ProfitMargin
Joined: 01 Aug 2013
Total Posts: 285
26 Aug 2013 09:30 PM
Kohl? I keep hearing about his admin scripts who is he!?
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
26 Aug 2013 09:31 PM
He made a bad, popular admin skirpt
Report Abuse
ProfitMargin is not online. ProfitMargin
Joined: 01 Aug 2013
Total Posts: 285
26 Aug 2013 09:33 PM
:o Okay, uncle cntkillme what is his username? And why is his admin scrpt bad? My friend told me tat people think person229 is sloppy admin scrpt
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
26 Aug 2013 09:34 PM
person's is also bad.
His name is like kohlstophe or something, he's bannered cuz he mad bad script c:
(idk why he's banned)
Report Abuse
shonclub is not online. shonclub
Joined: 05 Sep 2009
Total Posts: 1331
26 Aug 2013 09:35 PM
He got banned for try to get ookers on roblox.
Report Abuse
ProfitMargin is not online. ProfitMargin
Joined: 01 Aug 2013
Total Posts: 285
26 Aug 2013 09:36 PM
e.o wot!?
Report Abuse
BlueTaslem is not online. BlueTaslem
Joined: 11 May 2008
Total Posts: 11060
26 Aug 2013 09:38 PM
cntkillme: The delay time is a matter of how long the delay was in starting the function call, not execution, and since you call one first, it's not surprising that it finished first since there's nothing going on in either function.
TL;DR: That's a really terrible way to show one is faster.

local t = {};
for i = 1, 10000 do
table.insert(t,math.random());
end


function one()
local s = 0;
for i,v in pairs(t) do
s = s + v;
end
return s;
end

function two()
local s = 0;
for i,v in ipairs(t) do
s = s + v;
end
return s;
end

print(".");

local time;
time = tick();
for j=1,1000 do
one();
end
print(tick() - time,1);

local time;
time = tick();
for j=1,1000 do
two();
end
print(tick() - time,2);


two takes 4% longer than one one 10,000 elements, and similar results are seen on 5,000 elements (~4%)
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
26 Aug 2013 09:41 PM
@Blue
Delays run on separate "threads", it's not going to wait for the first one to finish.
Report Abuse
BlueTaslem is not online. BlueTaslem
Joined: 11 May 2008
Total Posts: 11060
26 Aug 2013 09:42 PM
I know, that's not relevant, is it?
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
26 Aug 2013 09:43 PM
I read your thing wrong, oops c;
Report Abuse
BlueTaslem is not online. BlueTaslem
Joined: 11 May 2008
Total Posts: 11060
26 Aug 2013 09:49 PM
Oh, but relevant advice:
ipairs and pairs are both dreadfully slow.

function three()
local s = 0;
for i=1,#t do
local v = t[i];
s = s + v;
end
return s;
end

This is about three times faster than pairs/ipairs (although it only replaces the functionality of ipairs).
When ipairs is possible and you're worrying about efficient, use this.
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
26 Aug 2013 09:50 PM
You no mention next?
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image