how fast to 1 Billion ?

BlitzMax Forums/BlitzMax Beginners Area/how fast to 1 Billion ?

rod54(Posted 2005) [#1]
How fast does your BMAX system count to 1 billion?

sample code:
[code box]
Strict

Global a:Int = 0

Global start:Int = MilliSecs(),finish:Int

While( a < 1000000000)

a = a + 1

Wend

finish = MilliSecs()

Print "0 to 1 Billion in " + (finish - start) + " milliseconds"

[/code box]


rod54(Posted 2005) [#2]
see if I can do this code bos thing right




rod54(Posted 2005) [#3]
Here is the result with my system

Process complete
C:/BlitzMax/BlitzMaxCore104/tmp/untitled1.exe
0 to 1 Billion in 5875 milliseconds

Process complete

This is great ... and old c++ compiler (borland ver 4.52)
I compilied a test for was running 7 seconds.

Ran a C++ compiled program at work on a linux system
we have which are dual 3.2Gig Xeon processors that
cranked out 0 - 1.0e+9 in .6 seconds


JoJo(Posted 2005) [#4]
With my slow system it took:
0 to 1 Billion in 125833 milliseconds

PII 400mhz/256mb ram/geforce4 mmx 460


col(Posted 2005) [#5]
I got

0 to 1 Billion in 18543 milliseconds

DEBUG ON

AthlonXP3000(@...) 512ram
Radeon9600 256meg


Booticus(Posted 2005) [#6]
I got

Process complete
C:/BlitzMax/tmp/untitled1.exe
0 to 1 Billion in 1723 milliseconds

Process complete

P4 2.4 ghz
512ram


Punksmurf(Posted 2005) [#7]
0 to 1 Billion in 2368 milliseconds (normal)

0 to 1 Billion in 19334 milliseconds (debug, what a difference!)

p4 HT 3ghz, 512mb
(office pc, so maybe there are some less-than-optimal components alltough the proc is quite cool... i'm at work now)


xlsior(Posted 2005) [#8]
0 to 1 Billion in 2952 milliseconds on Athlon 2800+


rod54(Posted 2005) [#9]
jojo... I would think you must have been in debug mode with that slow of time, Turn off debug and see if you get a better time, I would be interested in what you get with debug off too Col :)


Muttley(Posted 2005) [#10]
You're slowing yourself down there using Globals when they're not needed. ;)

Try this:
Strict 

Local a:Int = 0 

Local start:Int = MilliSecs(),finish:Int 

While( a < 1000000000) 

a = a + 1 

Wend 

finish = MilliSecs() 

Print "0 to 1 Billion in " + (finish - start) + " milliseconds" 

My machine: Dell Latitude C840, Windows XP SP2, 1.8GHz P4, 768MB Mem

Original version:
Debug mode: 33132ms
NoDebug mode: 2340ms

Local variable version:
Debug mode: 34155ms
NoDebug mode: 876ms

Muttley


rod54(Posted 2005) [#11]
Anybody think they can beat those dual Xeon processors
that cranked out (C++ code) a blistering 680 milliseconds

... ah technology today -- think about it ... counting to

1 billion before you could say the word 'one'


rod54(Posted 2005) [#12]
Local did drop me another 2.5 seconds on my 1Ghz Athlon

Process complete
C:/BlitzMax/BlitzMaxCore104/tmp/untitled1.exe
0 to 1 Billion in 3114 milliseconds

Process complete

Thanks,


rod54(Posted 2005) [#13]
what I dont understand is why my old borland C++ compilier
is taking 7 seconds ... I have all the optimized settings set as far as I know and her is the code.

[codebox}
#include <iostream.h>
#include <time.h>

int main()
{
long a = 0;
int seconds = 0;
time_t start,end;
cout << "Staring my count to 1 billion\n";
start = time(NULL);

do
{
a++;
} while (a < 1000000000);

end = time(NULL);
seconds = end - start;
cout << "0 to 1 billion is complete in " << seconds << " seconds\n";
return 0;
}
[/codebox]

anyway from the looks of it ... BMAX is great :)


skn3(Posted 2005) [#14]
btw, you can edit your posts. See the top right of each posting, there is an "edit" link.

Here is my result
0 to 1 Billion in 602 milliseconds



GameKing(Posted 2005) [#15]
Strict adds overhead
compiler defaults to int
for/next faster then while/wend
calculate before print




Enjoy


jkrankie(Posted 2005) [#16]
Compiling:untitled1.bmx
Linking:untitled1
Executing:untitled1
0 to 1 Billion in 5092 milliseconds
Done.

on a 700mhz g4 imac


Punksmurf(Posted 2005) [#17]
Thanks to the suggestion of using GLOBAL variables instead of LOCAL ones I got the idea of optimizing this loop a little further. I read somewhere that FOR .. = .. UNTIL .. would be faster than using FOR .. = .. TO .., so I figured this might apply to other loops as well. Also we can do x:+1 instead of x = x + 1. I put it all togehter in a (rather dirty, I admit) program, and the results were quite interesting.

I will refer to FOR .. = .. TO .. / NEXT as FOR-TO and to FOR .. = .. UNTIL .. / NEXT as FOR-UNTIL from here on.

Here are the GLOBAL vs LOCAL results:

WHILE loop and x = x + 1...
LOCAL: 548 milliseconds
GLOBAL: 2374 milliseconds

REPEAT loop and x = x + 1...
LOCAL: 545 milliseconds
GLOBAL: 2365 milliseconds

WHILE loop and x :+ 1...
LOCAL: 514 milliseconds
GLOBAL: 2032 milliseconds

REPEAT loop and x :+ 1...
LOCAL: 816 milliseconds
GLOBAL: 2034 milliseconds

FOR-TO loop
LOCAL: 524 milliseconds
GLOBAL: 2023 milliseconds

FOR-UNTIL loop...
LOCAL: 512 milliseconds
GLOBAL: 2039 milliseconds

As it was already stated GLOBAL variables are *very much* slower than LOCAL ones.


I will now compare the different aspects in the WHILE and REPEAT loops.
These are the same results as before (exept FOR/NEXT loops), but grouped otherwise to make it easy to compare the difference between x = x + 1 and x:=1

Using LOCAL, WHILE loop
x=x+1: 548 milliseconds
x:+1: 514 milliseconds

Using GLOBAL, WHILE loop
x=x+1: 2374 milliseconds
x:+1: 2032 milliseconds

Using LOCAL, REPEAT loop
x=x+1: 545 milliseconds
x:+1: 816 milliseconds

Using GLOBAL, REPEAT loop
x=x+1: 2365 milliseconds
x:+1: 2034 milliseconds

You can see that using the shortcut (x:+1) is a bit faster than the old way, except for the LOCAL, REPEAT-loop thingy. This is a bit weird, but of course anything may be influenced by other processes. There were no programs active when I ran this test, but windows keeps a lot of background processes. It might be a nice thing to run this test several times to get a better avarage.

The first time I ran this thing I had one process taking up 100% of one virtual processor (p4 HT) and then the x:+1 was more than twice as fast! Don't know what exactly causes this.


Next thing up is the comparisation between WHILE and REPEAT loops. Of couse I'm using the same results.

Using LOCAL and x = x + 1...
WHILE: 548 milliseconds
REPEAT: 545 milliseconds

Using GLOBAL and x = x + 1...
WHILE: 2374 milliseconds
REPEAT: 2365 milliseconds

Using LOCAL and x :+ 1...
WHILE: 514 milliseconds
REPEAT: 816 milliseconds

Using GLOBAL and x :+ 1...
WHILE: 2032 milliseconds
REPEAT: 2034 milliseconds

As you see there is not much difference, exept for the LOCAL and x:+1. This result showed odd earlier.

Now we got the WHILE and REPEAT loops finished, let's see how the FOR loops behave!

Since we've already seen the difference between GLOBAL and LOCAL variables the only thing left to compare is FOR-TO and FOR-UNTIL. Behold:

Using LOCAL variables
FOR-TO: 524 milliseconds
FOR-UNTIL: 512 milliseconds

Using GLOBAL variables
FOR-TO: 2023 milliseconds
FOR-UNTIL: 2039 milliseconds

There is no clear difference between these two, but the difference that there is is rather small.


As a last thing to compare I have for you are all the results, ordered by speed.

Using LOCAL, FOR-UNTIL loop: 512 milliseconds
Using LOCAL, WHILE loop and x :+ 1: 514 milliseconds
Using LOCAL, FOR-TO loop: 524 milliseconds
Using LOCAL, REPEAT loop and x = x + 1: 545 milliseconds
Using LOCAL, WHILE loop and x = x + 1: 548 milliseconds
Using LOCAL, REPEAT loop and x :+ 1: 816 milliseconds
Using GLOBAL, FOR-TO loop: 2023 milliseconds
Using GLOBAL, WHILE loop and x :+ 1: 2032 milliseconds
Using GLOBAL, REPEAT loop and x :+ 1: 2034 milliseconds
Using GLOBAL, FOR-TO loop: 2039 milliseconds
Using GLOBAL, REPEAT loop and x = x + 1: 2365 milliseconds
Using GLOBAL, WHILE loop and x = x + 1: 2374 milliseconds

The conclusion so-far is rather easy: use FOR-UNTIL where possible ;)

These results are, however, statistically of not-so-much use, because it was just one test I ran. If I can find some time tonight (now I really need to get back to my database since I don't suppose my boss would like to see me toying with blitz all day ;) ) to do this more properly.

Of couse I won't let you go home without some source. It's a bit dirty and hastly-done, but clear.



gameking: thanks for your suggestions, I will use them when I continue testing, alltough calculating before print and the declaration won't influence these benchmarks of course, because they happen 'outside' the time-tested code.
If 'strict' add overhead while executing I can't tell, but it's worth a try :)


Takuan(Posted 2005) [#18]
Interesting, didnt know Local vs. Global does make such a difference.
What about do the same but in a function and call that function a billion times.
Local is then generated and killed every function call?
If so, maybe its slower using locals?
Just a dumb question..


Punksmurf(Posted 2005) [#19]
Takuan: of course that is slower, because there is much overhead. first you call a function, which creates a new local variable and then distroys it and then must return to the main program.
I wonder however how you would implement this test which actually does the same thing but requires such a function to do it's job..



that doesnt compare to the other way people tried before in this topic

however, of course we can benchmark this whole variable construction/destruction thing:



This actually gives some odd results to me, the left column is the time of calling the function with the variable, the right column is the time of calling the other (empty) function. And I'm really not mistaken... anyone can shine any light on this?

6031 - 6731
6211 - 7305
6119 - 7256
6026 - 6817
6029 - 6992

edit: maybe I misunderstood you and were you wondering how a function which creates a local variable would compare with another function which calls a global variable. Got these results:

left = local var, mid = global var, right = no var

6059 - 6856 - 6789
6614 - 6689 - 6677
6002 - 6699 - 6830
6625 - 6779 - 6736
6000 - 7277 - 6665




rod54(Posted 2005) [#20]
Thanks on the note on how to edit... not sure why but I
wasn't seeing the edit link but now I am.. I definitiely need it because my fat fingers always get in the way and my brain obviously doen't know how to control them.


Steve Elliott(Posted 2005) [#21]
I get 1288 ms
Using Muttley's version I get 492 ms.

Pentium 4 HT, 3.2Ghz 1024Mb RAM


Curtastic(Posted 2005) [#22]
To make it more accurate, you should put a delay at the beginning.

Strict 

Local a:Int = 0 

Local start:Int 
Local finish:Int 

Delay 500

start = MilliSecs()

While( a < 1000000000) 

a = a + 1 

Wend 

finish = MilliSecs() 

Print "0 to 1 Billion in " + (finish - start) + " milliseconds"  



Pongo(Posted 2005) [#23]
Curious as to whether or not blitzmax does this any faster than Blitz3d.

I do not have blitzmax, but I get 1778 with blitz3d

Work machine: (wish it was home machine)
Dual 3.4 Xeon
4Gig Ram


Punksmurf(Posted 2005) [#24]
and what did you get with bmx then? would be way easier to compare if you posted that as well :)


AdrianT(Posted 2005) [#25]
I gert between 0 to 1 Billion in 2713 and 2834 milliseconds without debug in the various versions of code I tried. That was on a 4 year old Athlon 1200


col(Posted 2005) [#26]
Rod49:

Using the first program in this thread, I got-
0 to 1 Billion in 1514 milliseconds

with DEBUG OFF. Blimey!!

And using the program by GameKing:
0 to 1 Billion in 995 milliseconds
DEBUG OFF
Nice.

And the code by Coorrae:
0 to 1 Billion in 974 milliseconds
DEBUG OFF


Bot Builder(Posted 2005) [#27]
using coorea's which is the most accurate I get 918 on my new comp i built last week <:-)

AMD Athalon64 3500+
1GB HyperX RAM
Radeon X700 Pro 256mb


Najdorf(Posted 2005) [#28]
how fast to a billion? Gimme a few years and I'll make it... $:-)$


JoJo(Posted 2005) [#29]
Ok, did it with debug off.
0 to 1 Billion in 18151 milliseconds

PII 400mhz 128mb ram


Panno(Posted 2005) [#30]
Building untitled1
Compiling:untitled1.bmx
flat assembler version 1.51
3 passes, 2332 bytes.
Linking:untitled1.exe

Process complete
K:/BMAX/tmp/untitled1.exe
0 to 1 Billion in 3959 milliseconds

Process complete


Punksmurf(Posted 2005) [#31]
how fast to a billion? Gimme a few years and I'll make it... $:-)$

Of course you will then remember how I've always been your very best friend and such, right? =P


Najdorf(Posted 2005) [#32]
Of course, my friend, now get back working!


Punksmurf(Posted 2005) [#33]
work means cash... see if I get there first $-)


Will(Posted 2005) [#34]
0 to 1bil in 1015 millesecs (normal)
0 to 1bil in 18476 millesecs (debug)

wow what a difference!

Dual 2ghz G5


JoJo(Posted 2005) [#35]
From Coorrea code:

Debug off
0 to 1 Billion in 5189 milliseconds

Debug on
0 to 1 Billion in 118419 milliseconds

PII 400 mhz 256mb ram


rod54(Posted 2005) [#36]
Well this turned out to be an interesting link to see all the difference in times by machines etc...

thanks for all the input.


MattVonFat(Posted 2005) [#37]
I thought my computer was really slow at first but the 2nd modification ran at 623millisecs!


rdodson41(Posted 2005) [#38]
Macintosh duel G4

3065 secs in Bmx with this prog:

start=MilliSecs()
For i=0 To 1000000000
Next
finish=MilliSecs()-start
Print finish
End



Uber Lieutenant(Posted 2005) [#39]
0 to 1 Billion in 3708 milliseconds

I didn't expect a good result like that from my laptop.

Windows XP Sp1 (Sp2 is annoying)
Intel Pentium 4m 1.3GHz
256MB SDRAM
ATi Mobility Radeon 9000 (64MB VRAM)


Gavin Beard(Posted 2005) [#40]
0 to 1 Billion in 4073 milliseconds (norm)
0 to 1 Billion in 28799 milliseconds (debug)


Dreamora(Posted 2005) [#41]
Rich your system is cool *rofl*

1454 ms norm
5112 ms debug

Pentium - M ( 1.5 Ghz, old P-M with 1MB 2nd lvl cache )


PowerPC603(Posted 2005) [#42]
Using Coorrae's code:

0 to 1 Billion with debug ON: 26165 milliseconds
0 to 1 Billion with debog OFF: 725 milliseconds


Punksmurf(Posted 2005) [#43]
I did this test on a friends' computer lateley and he wrote the same thing in c++. I don't remember the exact details of what we did but I think it was a for-to loop and using local integers. He turned on al optimization options for his compiler (don't know which) (of course he did, it'd be stupid to leave them off right?) and c++ turned out to be 10-20 millisecs faster than bmx. total time was about 2500ms.


LeisureSuitLurie(Posted 2005) [#44]
'Original code
0 to 1 Billion in 15162 milliseconds
'With locals
0 to 1 Billion in 5034 milliseconds
'With locals and a for-next loop
0 to 1 Billion in 5409 milliseconds
'With locals and a repeat-until a=1000000000
0 to 1 Billion in 5208 milliseconds

Gave up on debug mode, as it was easily taking over a minute (?!?!?)

700mhz G4 iMac

I wonder why while wend is faster than the other loops...



@Rich A Dual G4 what?


Gandalfisgeordie(Posted 2005) [#45]
Using Coorrae's code:

Building untitled2
Executing:untitled2.exe
0 to 1 Billion in 462 milliseconds

Process complete

P4/ 3.4Ghz


Sarge(Posted 2005) [#46]
I got 550 with Muttley's code


Sensenwerk(Posted 2005) [#47]
0 to 1 Billion in 793 milliseconds

System: XP 2.09 GHz, 1 GB Ram

using this code:


Strict

Local start:Int = MilliSecs(),finish:Int

For Local a:Int = 0 Until 1000000000
a:+1
Next

finish = MilliSecs()

Print "0 to 1 Billion in " + (finish - start) + " milliseconds"


Snarkbait(Posted 2005) [#48]
0 to 1 Billion in 548 milliseconds

Looks like p4 of 3ghz and above are very,very fast. ;)

p4, 3.2Ghz, 1GB dual channel RAM


Arcadenut(Posted 2005) [#49]
Ok, I've optimized the code....

Strict 

Local start:Int = MilliSecs(),finish:Int 

For Local a:Int = 0 Until 1000000000
a:+1000000000 
Next

finish = MilliSecs() 

Print "0 to 1 Billion in " + (finish - start) + " milliseconds" 


Does it in 0 Milliseconds...


ImaginaryHuman(Posted 2005) [#50]
Original code, 10467 millisecs. Mac osX panther 1GHz G4 256mb ram


I also got 3498 millisecs with muttley's version

With arcadenut's version, adding 1 each loop not a billion, I get 1734 millisecs.


AarbronBeast(Posted 2005) [#51]
With Rod49s original code, I get:

0 to 1 Billion in 39684 milliseconds (Debug)
0 to 1 Billion in 17584 milliseconds (Release)

Using Muttley's "Local Variable" version, I get:

0 to 1 Billion in 39262 milliseconds (Debug)
0 to 1 Billion in 1308 milliseconds (Release)

Are these numbers correct? They seem weird compared to the others on here.

Mac OS X 10.4
PowerMac G5 Dual 2.3 GHz, 1Gb Ram


taumel(Posted 2005) [#52]
Hi,

i get 193ms on a p4 2.8gig with this...

Local a=0,timAkt=0,timAnf=MilliSecs()

While(a<1000000000) 
	a:+1;a:+1;a:+1;a:+1;a:+1;a:+1;a:+1;a:+1
Wend 

timAkt=MilliSecs()-timAnf
Print "From 0 to "+a+" (a Billion) in "+timAkt+" milliseconds." 

The interesting part was to compare this to other tools. Some of them took ages.


Greetings,

taumel


Ibmurai(Posted 2005) [#53]
I got:

0 to 1 Billion in 8530 milliseconds

With my iBook G4 1.2GHz

(YAY! First post ever! Bought BlitzMax yesterday)


RiK(Posted 2005) [#54]
1492 ms with locals, about ten times slower with globals!

1492 - wasn't that the year that Columbus bumped into the US whilst out looking for the east indies?


Oldtimefun(Posted 2005) [#55]
Using rod49's code:
0 to 1 Billion in 3606 milliseconds
0 to 1 Billion in 36192 milliseconds(debug)

Using Coorrae's code:

0 to 1 Billion in 2100 milliseconds
0 to 1 Billion in 35404 milliseconds(debug)

Using taumel 's code:

0 to 1 Billion in 794 milliseconds
0 to 1 Billion in 5942 milliseconds(debug)

with athlon xp2500


Tom(Posted 2005) [#56]
1446 with Coorraes code

Specs below


nawi(Posted 2005) [#57]
I get 2 seconds on Blitzmax and 3 seconds on c++


TeraBit(Posted 2005) [#58]
1737 with Coorraes code


Wiering(Posted 2005) [#59]
Coorrae's code becomes about 10% faster if you declare a right before the loop. Looking at the assembly, this compiles to add eax,1 instead of add esi,1. I would have expected a :+ 1 to be faster too, but it compiles to the same add eax,1 (instead of inc eax, which I think would be faster).

Strict 

Local start: Int 
Local finish: Int 

Delay 500

start = MilliSecs()

Local a: Int = 0
While (a < 1000000000) 
  a = a + 1 
Wend 

finish = MilliSecs() 

Print "0 to 1 Billion in " + (finish - start) + " milliseconds"  



WendellM(Posted 2005) [#60]
With Wiering's code, on my Athlon 3000+ under Win XP Pro SP2:

1465 BlitzMax 1.10


With the required, minor adjustments:

2061 Blitz3D 1.90


In both BlitzMax and Blitz3D, it makes no difference using While/Wend or For/Next, or whether the program was run in the IDE or as an Exe (both with no debug).


Curious, I tried my older, Microsoft Basics (code adjusted as needed). With them, there are differences between running in their IDE or as a compiled Exe, as well as using a While/Wend loop or a For/Next one.

I was surprised to see that compiled VB 5 (1997) is slightly faster than Blitz3D (though not as fast as BlitzMax):

In IDE:
67343 Visual Basic 5.0 SP3 (While/Wend)
12343 Visual Basic 5.0 SP3 (For/Next)

Compiled as Exe:
1921 Visual Basic 5.0 SP3 (While/Wend)
1734 Visual Basic 5.0 SP3 (For/Next)


And then there's good ol' QuickBASIC from 1988 <g>:

In IDE:
109296 QuickBASIC 4.5 (While/Wend)
51132 QuickBASIC 4.5 (For/Next)

Stand-alone Exe (no debug):
33007 QuickBASIC 4.5 (While/Wend)
32507 QuickBASIC 4.5 (For/Next)



rdodson41(Posted 2005) [#61]
3037 with duel G4's


WendellM(Posted 2005) [#62]
On my newly-acquired 933 MHz G4 with OS 10.3.9, I get 3330 with Wiering's code (though I didn't observe moving a's declaration to have any effect either on Mac or PC).