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 / Curious about how loops work

Author
Message
sneaky smith12
20
Years of Service
User Offline
Joined: 30th Apr 2006
Location: Like id tell you, oh wait i just did
Posted: 27th Oct 2010 22:51 Edited at: 27th Oct 2010 22:54
Now, I'm sure someone is going to laugh at that title.

I went ahead and made some code just to have a loop count to 100,000 and sync in each loop. My results I found out where that Do/Loops were on average were the slowest. Goto statements were unpredictable, and the others were pretty consistent with each other.

What causes the differences? Even though there is only about 2/5ths of a second in differences I would think they should be the exact same.



Typical results I get:


If at first you dont succeed, LOWER YOUR STANDARDS.
Kevin Picone
23
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Australia
Posted: 27th Oct 2010 22:57
The test is not counting the speed of the loops, but the page swapping speed.

BatVink
Moderator
23
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 27th Oct 2010 23:01
with those results, you can't really tell. Any number of Windows functions could have interfered. Even the order in which you run the tests can have an impact, for example it's very normal for a first test to take longer as it grabs resources and possibly the last to take longer as resources get fragmented.

sneaky smith12
20
Years of Service
User Offline
Joined: 30th Apr 2006
Location: Like id tell you, oh wait i just did
Posted: 28th Oct 2010 00:17
Quote: "with those results, you can't really tell. Any number of Windows functions could have interfered. Even the order in which you run the tests can have an impact, for example it's very normal for a first test to take longer as it grabs resources and possibly the last to take longer as resources get fragmented.
"


so now if I ran each test say 1,000 times and took the averages... wouldn't that fix the problem?

Quote: "The test is not counting the speed of the loops, but the page swapping speed."


Shouldn't the page swapping speed be the same regardless of the type of loop since there is nothing changing in the screen during the loop?

If at first you dont succeed, LOWER YOUR STANDARDS.
Daniel TGC
Retired Moderator
19
Years of Service
User Offline
Joined: 19th Feb 2007
Location: TGC
Posted: 28th Oct 2010 20:03 Edited at: 28th Oct 2010 20:04
Running the tests on a freshly formatted and installed machine Windows (not vendor supplied version which often comes with alot of their installed software). This mean no virus checkers, or any other 3rd party installed software.

This means you'll get a base comparison. However even eliments suchs as background indexing, can prevent a consistant score each time. The simple fact of the matter is, Windows operating systems are extremely busy places with alot going on the user doesn't see. To get an idea of this just do a control all delete and look at all the processes and services going on.
Kevin Picone
23
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Australia
Posted: 28th Oct 2010 20:20
Quote: "Shouldn't the page swapping speed be the same regardless of the type of loop since there is nothing changing in the screen during the loop?"


In theory, but we're not the only thing running on the system. Time is being eaten not purely by our program, but other applications in the background.

sneaky smith12
20
Years of Service
User Offline
Joined: 30th Apr 2006
Location: Like id tell you, oh wait i just did
Posted: 28th Oct 2010 20:55 Edited at: 28th Oct 2010 21:13
Quote: " Windows operating systems are extremely busy places with alot going on the user doesn't see"


True, but I'm not exactly sure how that effects the speed of the test if the RAM is sufficient to have excess RAM left over for the program and System Idle Process is 99% CPU usage.

Quote: "In theory, but we're not the only thing running on the system. Time is being eaten not purely by our program, but other applications in the background."


I guess I could switch it to something other than sync... maybe just add an integer, but I might need to make a bunch more loops to see if theirs a time difference.

EDIT: Actually, I just changed it to perform no calculations/commands that don't relate to the loop.

Results after 1 million loops taken once:


Source code:


If at first you dont succeed, LOWER YOUR STANDARDS.
Kevin Picone
23
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Australia
Posted: 28th Oct 2010 21:11
The longer the period, the less likely you're timing the loop on it's own. A smaller period will display a bias just as well, providing you average the results over time.

Indicium
18
Years of Service
User Offline
Joined: 26th May 2008
Location:
Posted: 28th Oct 2010 21:43
In my experience, the inc command is slow, replace it with loopcount = loopcount + 1

baxslash
Valued Member
Bronze Codemaster
19
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 28th Oct 2010 22:08
Quote: "In my experience, the inc command is slow, replace it with loopcount = loopcount + 1"

Really, I didn't know that! I always assumed it was quicker otherwise... why have it?

...OK so I did a test using this:


...and there was nothing in it (I ran it about 20 times)... I guess "inc" wins cause it's quicker to type?

Indicium
18
Years of Service
User Offline
Joined: 26th May 2008
Location:
Posted: 29th Oct 2010 00:02
I'll run my own test, to see if it's specific to my computer, but I'm sure it was slower...

But yeah, you're right... I don't know where I got that from lol.

sneaky smith12
20
Years of Service
User Offline
Joined: 30th Apr 2006
Location: Like id tell you, oh wait i just did
Posted: 29th Oct 2010 08:33
After seven trials with baxslash's code I got about 3 miliseconds slower with the Inc command.

If I changed it to inc count, 1 though it seemed to slow down even more. Like 10 ms slower.

If at first you dont succeed, LOWER YOUR STANDARDS.

Login to post a reply

Server time is: 2026-07-22 04:37:13
Your offset time is: 2026-07-22 04:37:13