Program Timing

General FreeBASIC programming questions.
Post Reply
Dik
Posts: 6
Joined: Aug 20, 2017 16:23

Program Timing

Post by Dik »

Laptop01
Single Double Integer Long Integer
(Seconds) (Seconds) (Seconds) (Seconds)
Addition 0.278 0.275 0.262 0.215
Subtraction 0.270 0.263 0.227 0.218
Multiplication 0.250 0.250 0.247 0.215
Division 0.519 0.799 4.104 4.068

Desktop01
Single Double Integer Long Integer
(Seconds) (Seconds) (Seconds) (Seconds)
Addition 0.137 0.137 0.137 0.139
Subtraction 0.137 0.137 0.137 0.139
Multiplication 0.138 0.139 0.137 0.137
Division 0.160 0.320 2.471 2.471


I don't know how to format this in a spreadsheet format; the results are from 100,000,000 timing loops for Single, Double, Integer and LongInteger numbers. Double with the exception of division executes faster than single, and long integers are as fast or faster than Integers. This is a consequence of the microprocessors. My desktop is nearly twice as fast as my old laptop (which was pretty fast - ASUS gamemachine). I'll post the source below, if I can.

dim as single sno1=20/6, sno2=10/6, sans
dim as double dno1=20/6, dno2=10/6, dans
dim as double ti, t1, t2, t3, t4, t5, t6, t7, t8
dim as double t9, t10, t11, t12, t13, t14, t15, t16
dim as integer ino1=10, ino2=5, ians
dim as integer counter
dim as longint lno1=10, lno2=5, lans

'Single Preciaion
ti=timer()

for counter=1 to 100000000
sans = sno1+ sno2
next

t1=timer-ti

ti=timer()

for counter=1 to 100000000
sans = sno1 - sno2
next

t2=timer-ti

ti=timer()

for counter=1 to 100000000
sans = sno1 * sno2
next

t3=timer-ti

ti=timer()

for counter=1 to 100000000
sans = sno1 / sno2
next

t4=timer-ti

'double precision
ti=timer()

for counter=1 to 100000000
dans = dno1+ dno2
next

t5=timer-ti

ti=timer()

for counter=1 to 100000000
dans = dno1 - dno2
next

t6=timer-ti

ti=timer()

for counter=1 to 100000000
dans = dno1 * dno2
next

t7=timer-ti

ti=timer()

for counter=1 to 100000000
dans = dno1 / dno2
next

t8=timer-ti

'Integer
ti=timer()

for counter=1 to 100000000
ians = ino1+ ino2
next

t9=timer-ti

ti=timer()

for counter=1 to 100000000
ians = ino1 - ino2
next

t10=timer-ti

ti=timer()

for counter=1 to 100000000
ians = ino1 * ino2
next

t11=timer-ti

ti=timer()

for counter=1 to 100000000
ians = ino1 / ino2
next

t12=timer-ti

'Long Integer

ti=timer()

for counter=1 to 100000000
lans = lno1+ lno2
next

t13=timer-ti

ti=timer()

for counter=1 to 100000000
lans = lno1 - lno2
next

t14=timer-ti

ti=timer()

for counter=1 to 100000000
lans = lno1 * lno2
next

t15=timer-ti

ti=timer()

for counter=1 to 100000000
lans = lno1 / lno2
next

t16=timer-ti


print using "Single Precision Addition: #.### seconds"; t1
print using "Single Precision Subtraction: #.### seconds"; t2
print using "Single Precision Multiplication: #.### seconds"; t3
print using "Single Precision Division: #.### seconds"; t4
print
print using "Double Precision Addition: #.### seconds"; t5
print using "Double Precision Subtraction: #.### seconds"; t6
print using "Double Precision Multiplication: #.### seconds"; t7
print using "Double Precision Division: #.### seconds"; t8
print
print using "Integer Addition: #.### seconds"; t9
print using "Integer Subtraction: #.### seconds"; t10
print using "Integer Multiplication: #.### seconds"; t11
print using "Integer Division: #.### seconds"; t12
print
print using "Long Integer Addition: #.### seconds"; t13
print using "Long Integer Subtraction: #.### seconds"; t14
print using "Long Integer Multiplication: #.### seconds"; t15
print using "Long Integer Division: #.### seconds"; t16

sleep
end
Dik
Posts: 6
Joined: Aug 20, 2017 16:23

Re: Program Timing

Post by Dik »

Should have added that 64 bit processors, generally, execute 64 bit things generally faster than 32 bit things... and other than storage, there may be little or nothing to gain from using a smaller data type.

Dik
sancho2
Posts: 547
Joined: May 17, 2015 6:41

Re: Program Timing

Post by sancho2 »

You can put code tags around your code and it will look like this:

Code: Select all

print "use code tags, thanks"
sleep
Post Reply