ID:151697
 
Out of sheer curiosity I decided to see if there was a difference between var/L[0] and var/L[]=new, and I was mildly surprised that the results weren't the same.

var/L[0] always got a 1.1 or 1 second calculation time, while var/L[]=new always got a 1 or 0.9 second calculation time.

After repeated tests my machine comes up with these results consistently.

This is the code I used. I want to see if other people come up with the same results:

var/TimeMark=0
proc/Mark(T)
world<<"Beginning Test: [T]"
// world<<"Operation started at [time2text(world.timeofday,"hh:mm:ss")]"
TimeMark=world.timeofday

proc/Report()
// world<<"Operation finished at [time2text(world.timeofday,"hh:mm:ss")]"
var/X=(world.timeofday-TimeMark)/10
world<<"Operation took [X] seconds \n"
return X

mob/verb/Test1()
var/Results[0]
var/X
for(var/y=1,y<=15,y++)
Mark()
for(var/i=1,i<=1000000,i++)
var/L[0]
X=Report()
if(!Results.Find("[X]"))
Results["[X]"]=1
else Results["[X]"]++
sleep(1)

for(var/Y in Results)
world<<"([Y] , [Results["[Y]"]])"



mob/verb/Test2()
var/Results[0]
var/X
for(var/y=1,y<=15,y++)
Mark()
for(var/i=1,i<=1000000,i++)
var/L[]=new
X=Report()
if(!Results.Find("[X]"))
Results["[X]"]=1
else Results["[X]"]++
sleep(1)

for(var/Y in Results)
world<<"([Y] , [Results["[Y]"]])"
                Profile results (total time)
Proc Name Self CPU Total CPU Real Time Calls
--------------- --------- --------- --------- ---------
/mob/verb/Test1 1.125 1.125 1.125 1
/mob/verb/Test2 1.068 1.068 1.068 1


In response to CaptFalcon33035
I can't do it right now, but wouldn't it be a good idea for people to list their specs?
In response to Flame Sage
Flame Sage wrote:
I can't do it right now, but wouldn't it be a good idea for people to list their specs?

No, not necessary... Just trying to see if one test runs faster than another.

Seeing if it is faster on a slower computer versus a faster computer doesn't matter, considering it will still show which one was worse.


EDIT: Anyway. It would appear that List=new is more efficient than List[0], which I THOUGHT was the same thing. Weird.
In response to AJX
AJX wrote:
EDIT: Anyway. It would appear that List=new is more efficient than List[0], which I THOUGHT was the same thing. Weird.

I have a guess that DM thinks it is trying to initialize a list with possible hard-coded contents, so it looks for them to load them when the line var/L[0] is reached, whereas with var/L[]=new, a new list is just initialized.
In response to CaptFalcon33035
CaptFalcon33035 wrote:
AJX wrote:
EDIT: Anyway. It would appear that List=new is more efficient than List[0], which I THOUGHT was the same thing. Weird.

I have a guess that DM thinks it is trying to initialize a list with possible hard-coded contents, so it looks for them to load them when the line var/L[0] is reached, whereas with var/L[]=new, a new list is just initialized.

No clue why.
Just a nice thing to know. :D
In response to AJX
Does anyone else get a memory leak when you do this for test 1
var/L[]=new
L+=list("Hi")

I tested it repeatedly and the memory usage went from
1340 to 5000
In response to Chowder
Chowder wrote:
Does anyone else get a memory leak when you do this for test 1
var/L[]=new
L+=list("Hi")

I tested it repeatedly and the memory usage went from
1340 to 5000

Well, it takes time for BYOND to clear out old list contents. That could have something to do with it. You're adding quite a lot of data there.
In response to AJX
Yeah but when
var/L[]=new
L+=list("Hi")
is tested the memory usage barely rises and goes back down
were as
var/L[0]
L+=list("Hi")
Goes up a lot and stays up
In response to Chowder
Chowder wrote:
Yeah but when
var/L[]=new
L+=list("Hi")
is tested the memory usage barely rises and goes back down
were as
var/L[0]
L+=list("Hi")
Goes up a lot and stays up

I see. I didn't realize you meant with ONE and not both.
I'll tinker around with this... Not sure.
In response to AJX
Tested this....
Absolutely no change for me in memory usage. For either.

Can you post the code you used? There's probably something you're overlooking.
In response to AJX
This is really weird

Make a new enviorment with this

var/TimeMark=0
proc/Mark(T)
world<<"Beginning Test: [T]"
// world<<"Operation started at [time2text(world.timeofday,"hh:mm:ss")]"
TimeMark=world.timeofday

proc/Report()
// world<<"Operation finished at [time2text(world.timeofday,"hh:mm:ss")]"
var/X=(world.timeofday-TimeMark)/10
world<<"Operation took [X] seconds \n"
return X

mob/verb/Test1()
var/Results[0]
var/X
for(var/y=1,y<=15,y++)
Mark()
for(var/i=1,i<=1000000,i++)
var/L[0]
L+=list("Hi")
X=Report()
if(!Results.Find("[X]"))
Results["[X]"]=1
else Results["[X]"]++
sleep(1)

for(var/Y in Results)
world<<"([Y] , [Results["[Y]"]])"



mob/verb/Test2()
var/Results[0]
var/X
for(var/y=1,y<=15,y++)
Mark()
for(var/i=1,i<=1000000,i++)
var/L[]=new
L+=list("Hi")
X=Report()
if(!Results.Find("[X]"))
Results["[X]"]=1
else Results["[X]"]++
sleep(1)

for(var/Y in Results)
world<<"([Y] , [Results["[Y]"]])"

Nothing else
Then run it and check its memory consumption
It starts with around 10k
Minimise it and it jumps down to 2k memory
Then run the test 1 note the memory
Restart it and do the same for test 2
Note the memory usage

Very weird that the memory jumps down so much if you minimize it o.o
In response to Chowder
Chowder wrote:
Very weird that the memory jumps down so much if you minimize it o.o

Lots of the memory is used drawing the visuals, interface, etc.

I'll test it shortly and post back what i see.

Ok. Ran the test...

These are all in order... Wtf lol.

Just dream seeker: 11.6k
While running test1: 11.6k
While minimized: 1.4k
After un-minimizing: 3.5k <--- WTF? lol.
While running test2: 4.2k
After running test2: 4.2k
After minimizing after running test2: 1.4k
After un-minimizing: 3.1k.. lol wtf?

So I have no memory leak, but the memory consumption of dream seeker is kinda crazy. lol.
What version of BYOND are you using? That is likely the be the source of this problem.
In response to AJX
Yeah but after its restored the memory doesn't go back up.
In response to Chowder
Chowder wrote:
Yeah but after its restored the memory doesn't go back up.

Yea that is weird lol.

I dunno, I'm going to go post in BYOND Features about it, see what the higher ups have to say.
In response to AJX
I always run on the latest version which is currently 450.1032
o.o

Anyways, The second method was already decided to be better.
Its just another reason to use it
In response to Chowder
Chowder wrote:
I always run on the latest version which is currently 450.1032
o.o

Anyways, The second method was already decided to be better.
Its just another reason to use it

Minutely. And I'm not even sure why that is the case. But yep!

And as for the memory thing... I don't even know. -.-
In response to AJX
It looks like its pre-loading options and messages and other things in the memory that are getting released when you minimize and its not bothering to reload it when you restore it
Test1 (0.9,12) (1,3)
Test2 (0.9,12) (0.8,3)


Appears to be exactly .1 faster.