Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / Array vs Memblocks [speed test]

Author
Message
Daniel TGC
Retired Moderator
19
Years of Service
User Offline
Joined: 19th Feb 2007
Location: TGC
Posted: 28th Dec 2011 13:50 Edited at: 28th Dec 2011 16:17
Another speed test I've written has thrown up some interesting results. People again always tell me that memblocks are faster than arrays. So I put it to the test with four data types, bytes, words, dwords and floats.

this is the code I used, feel free to pick it over and point out any errors I may have made, I did write this program quickly.



The results are as follows:



This is Booma's test, I assume using the same code I did.

Booma
17
Years of Service
User Offline
Joined: 29th Mar 2009
Location:
Posted: 28th Dec 2011 15:54 Edited at: 28th Dec 2011 16:16
@Daniel TGC

Very interesting comparison
MrValentine
AGK Backer
15
Years of Service
User Offline
Joined: 5th Dec 2010
Playing: FFVII
Posted: 28th Dec 2011 21:18
Would be nicer if you changed the colour of the results between red and black to show which result was superior hehe

Daniel TGC
Retired Moderator
19
Years of Service
User Offline
Joined: 19th Feb 2007
Location: TGC
Posted: 28th Dec 2011 22:53
sure would be! Shame I'm too lazy isn't it
MrValentine
AGK Backer
15
Years of Service
User Offline
Joined: 5th Dec 2010
Playing: FFVII
Posted: 28th Dec 2011 23:22 Edited at: 28th Dec 2011 23:23
Lol.meant to say red and green... weird...

EDIT

You lazy?... Nah your kidding...

Max P
16
Years of Service
User Offline
Joined: 23rd Jan 2010
Location:
Posted: 29th Dec 2011 11:45 Edited at: 29th Dec 2011 11:50
For everyone, here is a version with colors. I also added the poke/peek commands from the matrix1Util.
The fastest way is to use pointers:

But I don't know how to read single bytes, words and floats using them.





Ashingda 27
18
Years of Service
User Offline
Joined: 15th Feb 2008
Location:
Posted: 1st Jan 2012 17:27
Very interesting, I may have to try memblock on some of my functions to try and get some more speed out of it.

Dar13
18
Years of Service
User Offline
Joined: 12th May 2008
Location: Microsoft VisualStudio 2010 Professional
Posted: 3rd Jan 2012 19:58 Edited at: 3rd Jan 2012 19:59
@MaxP
Wouldn't peeking/poking a byte be like this

with make memory(4) for words, make memory(8) for dwords?

EDIT: fixed an error in my code. Otherwise it'd try reading a NULL pointer.

Stormwire
15
Years of Service
User Offline
Joined: 3rd Sep 2010
Location:
Posted: 4th Jan 2012 23:24 Edited at: 4th Jan 2012 23:25
Here is mine. So from reading this arrays read faster while memblocks write faster? If so which is better to use?

MrValentine
AGK Backer
15
Years of Service
User Offline
Joined: 5th Dec 2010
Playing: FFVII
Posted: 4th Jan 2012 23:33
I like my influence on this ^^ hey lookie the italian flag >.<

hmm this does beg the question... so which methods are best assigned to what things?

from what I have gathered using memblocks for save points would be good but then loading them would be slightly slow... hmm

Benjamin
23
Years of Service
User Offline
Joined: 24th Nov 2002
Location: France
Posted: 5th Jan 2012 00:25
Logically it should be fastest to both read and write directly with pointers, followed by arrays (bounds check) and lastly memblocks (memblock exist check and bounds check), but apparently this is not the case with DBPro.



Support a charitable indie game project!
WLGfx
18
Years of Service
User Offline
Joined: 1st Nov 2007
Location: NW United Kingdom
Posted: 5th Jan 2012 09:43
Interesting result from this test. At the end of the day Arrays would still be much better if you're dumping data into them to read in time critical code. Memblocks got me curious though, just to read the statement READ MEMBLOCK DWORD is a lot compared to myvar=*ptr, but they're faster too.

I still suppose that pointers are still using the old call a function to call another function, etc to read/write some data.

Mental arithmetic? Me? (That's for computers) I can't subtract a fart from a plate of beans!
Warning! May contain Nuts!
Chris Tate
DBPro Master
17
Years of Service
User Offline
Joined: 29th Aug 2008
Location: London, England
Posted: 7th Jan 2012 13:20
Quote: "So from reading this arrays read faster while memblocks write faster? If so which is better to use?"


Tough question, there is a lot to consider. It depends what we are doing with the data. We'd need to figure out if we need to expand and contract the amount of data, where the data is coming from and how often it needs to be loaded, and how complex it is can be considered; also; whether we want to copy a series of data frequently with copy memblock rather than using a manual FOR loop with an array.

As for data management, the Make Memblock is slower than the Dim command. The Array Count functions is slower than storing the count in a variable; but I'm not sure how slow the Memblock Size command is.

Reading & writing a variable is obviously faster than both memblocks and arrays (according to my tests), so calculations are best performed with variables containing local copies of the data from the array or memblock.

I am suprised that Memory pointers work as slow as shown above.

BatVink
Moderator
23
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 7th Jan 2012 16:28
A couple of things regarding the code:

You should SYNC ON. Otherwise the program may SYNC mid-test without you being aware.

You should run through all tests more than once, and in different sequences. Otherwise you may not account for other system processes, the way the operating system is handling memory swapping and other technicalities. Even multiple tests is still not 100% accurate but you at least have a better sample of distributed data points.

You may still get the same results but at least you have eliminated some points of contention. If you analyse the numerous repeat tests, you should also be able to calculate the tolerance of the results. You could even take it to the extreme and plot a scatter graph of all the data points, which is actually very easy using Excel or Google Docs. Running it for 10 minutes or more would get you a lot of data to refine the results and variance in the results.

Nomad Soul
Moderator
19
Years of Service
User Offline
Joined: 9th Jan 2007
Location: United Kingdom
Posted: 10th Feb 2012 16:39
I know a much better way of checking which is faster and requires no code at all .....

ASK LEE !!!!

Login to post a reply

Server time is: 2026-07-09 21:19:46
Your offset time is: 2026-07-09 21:19:46