simple CPU Benchmark with comparisons + 5%FB speed boost tip

Post your FreeBASIC source, examples, tips and tricks here. Please don’t post code without including an explanation.
TESLACOIL
Posts: 1769
Joined: Jun 20, 2010 16:04
Location: UK
Contact:

simple CPU Benchmark with comparisons + 5%FB speed boost tip

Post by TESLACOIL »

ADDED

if you post results can you please include the full name of your CPU run CPUid if your not 101% sure


* speedtest 8 is the main test

*the multicore speedtest ( a few posts down ) only seems to work with winxp

CPUid Fritzbench & speedtest7.exe ( the exe is downloadable, so if granny or your gerbil want to run the test they can )
http://asimov1.wikispaces.com/Download+Benchmarks

Code: Select all


    'speed test version 8
    '#include "windows.bi"
    'SetPriorityClass( GetCurrentProcess(), HIGH_PRIORITY_CLASS )

    dim i as ULONGINT
    dim mem as integer
    dim st as  double
    dim fin as  double
    dim mips as double
    dim q as integer
    cls:color 7
    ?" paused here so you can mess with priority in windows task manager"
    input "...hit enter to start";q
    mem = FRE

    ?:?" Free memory:" ;mem  \ (1024 * 1024); " megabytes"
    ?:?" starting Free Basic speed test......approx 10 seconds":?:sleep 100

    st = TIMER :?" start   "; st , timer

    for i = 1 to 2500000000:next i

    fin = TIMER :?" finish  "; fin , timer

    ?: color 13: ?" time = " ;fin-st;" i = ";i;" how many loops done in total"

    i=i/1000000
    mips = i/ (fin-st)

    ?:?" mips = "; mips; " FreeBASIC for next loop instructions X 1 million"
    color 15:?:

    '?""
    ?" 500 Mhz Pent III =  68"
    ?" Celeron 2600     = 180"
    ?" Sepmron 2600+    = 305"
    ?" Athalon 2000+    = 330"
    ?""
    ?" Atom N450 2 core = 235 * task manager cpu usage was showing 50%   "
    ?" Atom N450 2 core = 335 * running 2 progs at once cpu usage 100% "
    ?
    ?" hit enter to exit":


    sleep: end



    'DIM variable AS ULONGINT
    'A 64-bit unsigned whole-number data type. Can hold values from 0 to 18 446 744 073 709 551 615







Original post

Simple speed Benchmark with comparisons
if you have a dual core or an i7 plz post your times, so i can add them



Code: Select all


'speed test version 3
dim i as ULONGINT
dim mem as integer
dim st as  SINGLE 
dim fin as  SINGLE
dim mips as single

cls:color 7

mem = FRE

?:?" Free memory:" ;mem  \ (1024 * 1024); " megabytes"

?:?:?:?" starting speed test.........approx 10 seconds":?:sleep 100

st = TIMER :?" start   "; st , timer

for i = 1 to 1000000000 : next i

fin = TIMER :?" finish  "; fin , timer

?: color 10: ?" time = " ;fin-st

i=i/1000000
mips = i/ (fin-st)

?:?:?:?" mips = "; mips; "   million for next loop instructions"
color 7:?:
?" Celeron 2600    = 180"
?" Atom N450       = 235"
?" Sepmron 2600+   = 305"
?
?" hit enter to exit":


sleep: end

http://www.cpubenchmark.net

added thanks MichaelW
this code below can boost the performance of your progs by about 5% and prolly more importantly help ensure that your FB prog is the one that stays hogging the cpu

Code: Select all

#include "windows.bi"
SetPriorityClass( GetCurrentProcess(), HIGH_PRIORITY_CLASS )


added


thread " what pc have you got"
http://www.freebasic.net/forum/viewtopi ... 552#155552

speedtest7 is available for dload in exe form (stripped down version of 6)
should any who doesn't have FB installed want try it

http://freebasicportal.wikispaces.com/FB+app%27s
Last edited by TESLACOIL on Dec 26, 2012 12:58, edited 21 times in total.
D.J.Peters
Posts: 8586
Joined: May 28, 2005 3:28
Contact:

Post by D.J.Peters »

sorry but this isn't a CPU benchmark
you test only how often your multitask OS gives your application task a time slice.

you know ?

Joshy
TESLACOIL
Posts: 1769
Joined: Jun 20, 2010 16:04
Location: UK
Contact:

yes, its only just very simple test. But its quite revealin

Post by TESLACOIL »

yes, its only just very simple test. But its quite revealing in its own way. Its as much about testing FreeBASIC as the system itself.

" i want to get some figures back for a spread of systems so i can calibrate & develop a more accurate and sophisticated FB benchmark tool "

even simple progs like this get you in the ball bark & give you a starting point

its been a fun hobby over the years as computer speeds have risen steadily
badidea
Posts: 2586
Joined: May 24, 2007 22:10
Location: The Netherlands

Post by badidea »

Use doubles for timers not singles. I get mips = inf under linux.
MichaelW
Posts: 3500
Joined: May 16, 2006 22:34
Location: USA

Post by MichaelW »

D.J.Peters wrote:you test only how often your multitask OS gives your application task a time slice.
Running under Windows, unless there is an active higher-priority process, with the small priority boost that a foreground process gets, a normal-priority foreground process should be able to run more or less continuously.

TESLACOIL,

Under Windows you can test this by comparing the times between the benchmark running at a normal priority, and then running at an elevated priority, set by placing these two statements at the top of your source:

Code: Select all

#include "windows.bi"
SetPriorityClass( GetCurrentProcess(), HIGH_PRIORITY_CLASS )
Testing on my Windows 2000 P3 system, HIGH_PRIORITY_CLASS increased the mips score by only ~0.3%.
TESLACOIL
Posts: 1769
Joined: Jun 20, 2010 16:04
Location: UK
Contact:

btw

Post by TESLACOIL »

btw how many mips did you get , & what spec is your machine.




out of interest if you multiply the mips , in my prog by roughly 50 that will give you flops as measured by professional benchmark progs

that figure kind of makes sense as the mips in my prog is freebasic mips or rather a for next loop. I only did some rough research so don't hold me to this. Benchmarking and real word performance are 2 very different things. Real world performance is 10 to 50% of benchmark performance you see in pro benchmark tools



It is the performance of freebasic im mainly after with my prog. this can be measured very well. But is also gives you a rough guide to your systems speed

though multicore machines may under perform in this test , then again they prolly make up for it by having better flow to and from the cpu

if someone with dual and quad core post the results we will be able to see how accurate it is as a rough measure of cpu performance


ill redo the code , its a little bit sloppy and im a Linux virgin. ill prolly test a number of things individually, for next loop , do loop , loading and reading an array and dumping to file for good measure. As well as some simple graphics tests.

btw screen mode and color depth can have a huge impact on how fast graphical code runs even if the window remains the same size. which is why i left this in console mode with no output to the screen while its running
MichaelW
Posts: 3500
Joined: May 16, 2006 22:34
Location: USA

Post by MichaelW »

TESLACOIL wrote:btw how many mips did you get , & what spec is your machine.
My now 11-year old test system has a 500 MHz Pentium III processor. For three consecutive trials at each priority I get:

Code: Select all

NORMAL_PRIORITY_CLASS:
mips =  62.45426
mips =  62.4695
mips =  62.48475

HIGH_PRIORITY_CLASS:
mips =  62.60699
mips =  62.59169
mips =  62.62231
These results indicate that the benchmark is running essentially continuously.

Here is the assembly code for the empty for-next loop that you are timing:

Code: Select all

mov dword ptr [ebp-12], 1
mov dword ptr [ebp-8], 0
.Lt_003E:
.Lt_003C:
add dword ptr [ebp-12], 1
adc dword ptr [ebp-8], 0
.Lt_003B:
cmp dword ptr [ebp-8], 0
jb .Lt_003E
ja .Lt_0048
cmp dword ptr [ebp-12], 1000000000
jbe .Lt_003E
.Lt_0048:
It includes only a very small subset of the processor instruction set, and none of the slower instructions.
It is the performance of freebasic im mainly after with my prog. this can be measured very well. But is also gives you a rough guide to your systems speed
Your mips score is much more dependent on the system speed than it is on the choice of compiler. I don’t have time to do this ATM, but I think this can be demonstrated by comparing your code against a compiler-optimized C version.
marcov
Posts: 3455
Joined: Jun 16, 2005 9:45
Location: Netherlands
Contact:

Post by marcov »

MichaelW wrote:
D.J.Peters wrote:you test only how often your multitask OS gives your application task a time slice.
Running under Windows, unless there is an active higher-priority process, with the small priority boost that a foreground process gets, a normal-priority foreground process should be able to run more or less continuously.
Running under Windows XP yes.

Under Vista/W7 you will first have to adjust the power scheme to "ALWAYS ON"
TESLACOIL
Posts: 1769
Joined: Jun 20, 2010 16:04
Location: UK
Contact:

what are the other tags for this ?

Post by TESLACOIL »

btw what are the other tags for this ? LOW_ & REALTIME_

HIGH_PRIORITY_CLASS

pause and priority added


handy bit of code to know
, it seems to work. i used task manager to alter priority and also tried this code and the results where the same as far as i could tell

Code: Select all



'speed test version 4
#include "windows.bi"
SetPriorityClass( GetCurrentProcess(), HIGH_PRIORITY_CLASS )

dim i as ULONGINT
dim mem as integer
dim st as  SINGLE 
dim fin as  SINGLE
dim mips as single
dim q as integer
cls:color 7
input " paused here so you can mess with priority in windows task manager...hit enter to start";q
mem = FRE

?:?" Free memory:" ;mem  \ (1024 * 1024); " megabytes"

?:?:?:?" starting speed test.........approx 10 seconds":?:sleep 100

st = TIMER :?" start   "; st , timer

for i = 1 to 1000000000 : next i

fin = TIMER :?" finish  "; fin , timer

?: color 10: ?" time = " ;fin-st

i=i/1000000
mips = i/ (fin-st)

?:?:?:?" mips = "; mips; "   million for next loop instructions"
color 7:?:
?" 500 Mhz Pent III    = 62"
?" Celeron 2600       = 180"
?" Atom N450           = 235"
?" Sepmron 2600+    = 305"
?
?" hit enter to exit":


sleep: end



'DIM variable AS ULONGINT
'A 64-bit unsigned whole-number data type. Can hold values from 0 to 18 446 744 073 709 551 615

i was unsure how to add the machine code

its was good to have the 500mhz machine in there to extend the spread on the low end



when i messed with the priority my main machine ran 168 to 183 , im sure priority will kick in more if the is machine is overloaded




cltr+alt +del brings up the task manager , i have it minimized with the little green box showing cpu usage on the task bar
TESLACOIL
Posts: 1769
Joined: Jun 20, 2010 16:04
Location: UK
Contact:

just done some more tests

Post by TESLACOIL »

just done some more tests

The N450 atom , 235 MIPS , or should i say megafloops? (FB loops) is a 1.6ghz cpu with 2 cores. But the cpu usage was 50% by the task managers little green bar

when over loaded , 2 tests run at once, it returned 168 floops per prog
so when the 2 cores are working at 100% it knocks out 336 megafloops
or 1.4 times faster

this is inline with my rule of thumb that multi core machine only use about 70% of the capacity of each chip when maxed out

70% x 2 = 140%
70% x 4 = 280%

modern architecture must also play a significant role. You can no longer easily count or guess the speed of your computer from the gigahertz of the chip. Its nice to have a simple benchmark prog like this to flush out the real world truth in a fistful of seconds.
MichaelW
Posts: 3500
Joined: May 16, 2006 22:34
Location: USA

Post by MichaelW »

I have now compared your code to this C version:

Code: Select all

#include <windows.h>
#include <stdio.h>
#include <conio.h>

//=================================================================

double timer()
{
    static LARGE_INTEGER pc_freq, pc_count;
    if (pc_freq.QuadPart == 0)
    {
        QueryPerformanceFrequency(  &pc_freq );
    }
    QueryPerformanceCounter(  &pc_count );
    return (double) pc_count.QuadPart / (double) pc_freq.QuadPart;
}

int main()
{
    double t1,t2;
    unsigned long long i;

    t1 = timer();
    t1 = timer();
    printf( "%f\n", t1 );
    for ( i = 1 ;  i < 1000000000 ; i++ );
    t2 = timer();
    printf( "%f\n", t2 );
    printf( "%f\n", t2 - t1 );
    getch();
    return 0;
}
Running on my P3 test system, typical times were:

Your code:

16.00781

The C version compiled with GCC 3.4.5, no optimization:

19.711048

The C version compiled with GCC 3.4.5, -O3 optimization:

8.010960

The C version compiled with the Microsoft VC++ 2003 compiler, /O2 /G6 optimization:

6.049316
TESLACOIL
Posts: 1769
Joined: Jun 20, 2010 16:04
Location: UK
Contact:

very interesting to see the difference in time

Post by TESLACOIL »

very interesting to see the difference in times between C's & FB

my FB code runs 2 or 3 times slower than c. Not something for FB to be too ashamed of.

FBIde 0.4.6 , Version 0.20.0 (08-10-2008) for win32

I noticed that if you halt the program for a moment before starting the test loop the loops per second improved. I guess this is the computer shaking its head and getting and getting itself together have cleared its buffers after launching the exe

you might shave a second or so of the C times

also check cpu usage is 100% , its possible that the fastest c code is not taxing your system. If you launch 2 or more speed tests at once you can see how well the computer handles being overloaded. It is possible that optimized C might be dancing in closer harmony with the systems way of doing things & may be faster still by comparison when the cpu is overloaded.






with my FB code loops 1 or 2 zeros smaller result is slower 145mips the worst. 180 mips standard loop length.Add 1 or 2 zeros it runs slightly faster 200 . The very fastest was 210 mips

Turned pc off to let cpu cool , closed all user progs , lo res desktop and colours, mouse positioned off screen, priority set to realtime added 1 extra zero.

best result = 210.8 mips @ 4.5secs 45% faster than my worst ever time

Intel Celeron 2.60GHz benchmark = 290 at
http://www.cpubenchmark.net/cpu_list.php
TESLACOIL
Posts: 1769
Joined: Jun 20, 2010 16:04
Location: UK
Contact:

Speed test version 6

Post by TESLACOIL »

Speed test version 6.

the athalon 2000 was a skip find ! , the heat sink was a furball cpu temp 90c+ , after a spring clean the system is 100% stable at 45c...bargain !

Code: Select all

'speed test version 6 
'#include "windows.bi"
'SetPriorityClass( GetCurrentProcess(), HIGH_PRIORITY_CLASS )

dim i as ULONGINT
dim mem as integer
dim st as  double 
dim fin as  double
dim mips as double
dim q as integer
cls:color 7
?" paused here so you can mess with priority in windows task manager"
input "...hit enter to start";q
mem = FRE

?:?" Free memory:" ;mem  \ (1024 * 1024); " megabytes"
?:?" starting Free Basic speed test......approx 10 seconds":?:sleep 100

st = TIMER :?" start   "; st , timer

for i = 1 to 1000000000:next i

fin = TIMER :?" finish  "; fin , timer

?: color 10: ?" time = " ;fin-st

i=i/1000000
mips = i/ (fin-st)

?:?" mips = "; mips; " FreeBASIC for next loop instructions X 1 million"
color 15:?:

'?""
?" 500 Mhz Pent III =  68"
?" Celeron 2600     = 180"
?" Sepmron 2600+    = 305"
?" Athalon 2000+    = 330"
?""
?" Atom N450 2 core = 235 * task manager cpu usage was showing 50%   "
?" Atom N450 2 core = 335 * running 2 progs at once cpu usage 100% "
?
?" hit enter to exit":


sleep: end

Last edited by TESLACOIL on Apr 01, 2011 2:13, edited 1 time in total.
badidea
Posts: 2586
Joined: May 24, 2007 22:10
Location: The Netherlands

Post by badidea »

I get ~400 mpis on a Dual core @ 3Ghz (E8300), running winXP.

For some applications, the memory speed can more important. A processor can typically process data 10x faster then that the memory can supply that data. You could build a memory test as well: Just copy big (bigger then cpu cache) arrays several times.

edit: Same system running Ubuntu 10.04 LTS (64bit): 415...430 mips

And use uinteger for fre, else i get Free memory: -1311 megabytes.
TESLACOIL
Posts: 1769
Joined: Jun 20, 2010 16:04
Location: UK
Contact:

Post by TESLACOIL »

at http://www.cpubenchmark.net/cpu_list.php

Intel Core2 Duo E8300 @ 2.83GHz 1975 their benchmark system
Intel Celeron 2.60GHz 290
6.8faster

Intel Core2 Duo E8300 @ 2.83GHz 400 mips
Intel Celeron 2.60GHz 180 mips
2.2x faster


badidea doublecheck your cpu is working 100% , u should be 600 to 700 mips im sure with that E8300 of yours. my eyes had to skip over the linux result :-(

launch 2 or 4 tests at once , add all the mips up , that's how i found out how fast my dual core N450 was. I bet you come back with 600+mips then

its good to be aware of when your cpu is underutilized, that's the trouble with multi cpu or multi cores. You need apps written for them to get the most out.

FB bench tests maybe like this

for next loops
fill a screen with pixels 1 at time
scroll lines of text
read n write 1 meg files
read n write 1k files
have figures for & times for each


just to give people a feel for the speedlimit of their code

plausable idea
one way to increase the speed of some fb games on a dual core machine may be to have 2 exes, the main one and a smaller one chewing on some data in the background, music ? , ai ? even a keyboard routine , say fire rocket , background prog detects key press ,play rocket sound and then informs main prog action has been taken a few ms delay being unimportant. This could help the main prog scroll / fly more smoothly esp if it had higher priority
Post Reply