my times
Code: Select all
division ==================================
=== single ===
division using default single precision: time 2.368007199999738 seconds sum = 37.98161
division using reduced single precision: time 1.382252299999891 seconds sum = 37.98161
reduced single precision division is 1.713151209804408 times faster
=== double ===
division using default double precision: time 2.3717587000001 seconds sum = 37.98231426240503
division using reduced double precision: time 2.177881900000102 seconds sum = 37.98231426240503
reduced double precision division is 1.089020805030791 times faster
sqr ==================================
=== single ===
sqr using default single precision: time 3.750732999999855 seconds sum = 2.108227e+007
sqr using reduced single precision: time 1.776602799999637 seconds sum = 2.108227e+007
reduced single precision sqr is 2.111182645890585 times faster
=== double ===
sqr using default double precision: time 3.748969399999623 seconds sum = 21082008.97391792
sqr using reduced double precision: time 3.161076800000046 seconds sum = 21082008.97391793
reduced double precision sqr is 1.185978588055681 times faster
Code: Select all
dim as ushort oldcw, cwdouble=&h27F, cwsingle=&h7F
dim as double t1, t2, t3, t4
print "division =================================="
print "=== single ==="
scope
dim as single x=3.141592653589793, y, z, s
t1=timer
for i as integer=1 to 3000
s=0
for j as integer=1 to 100000
s+=x/j
next
next
t2=timer
t3=t2-t1
print "division using default single precision: time ";t3;" seconds","sum = ";s
t1=timer
asm
fstcw word ptr [oldcw]
fldcw word ptr [cwsingle] 'set FPU precision to single
end asm
for i as integer=1 to 3000
s=0
for j as integer=1 to 100000
s+=x/j
next
next
asm
fldcw word ptr [oldcw] 'restore control word
end asm
t2=timer
t4=t2-t1
print "division using reduced single precision: time ";t4;" seconds","sum = ";s
print "reduced single precision division is ";t3/t4;" times faster"
end scope
print "=== double ==="
scope
dim as double x=3.141592653589793, y, z, s
t1=timer
for i as integer=1 to 3000
s=0
for j as integer=1 to 100000
s+=x/j
next
next
t2=timer
t3=t2-t1
print "division using default double precision: time ";t3;" seconds","sum = ";s
t1=timer
asm
fstcw word ptr [oldcw]
fldcw word ptr [cwdouble] 'set FPU precision to double
end asm
for i as integer=1 to 3000
s=0
for j as integer=1 to 100000
s+=x/j
next
next
asm
fldcw word ptr [oldcw] 'restore control word
end asm
t2=timer
t4=t2-t1
print "division using reduced double precision: time ";t4;" seconds","sum = ";s
print "reduced double precision division is ";t3/t4;" times faster"
end scope
print "sqr =================================="
print "=== single ==="
scope
dim as single x=3.141592653589793, y, z, s
t1=timer
for i as integer=1 to 3000
s=0
for j as integer=1 to 100000
s+=sqr(j)
next
next
t2=timer
t3=t2-t1
print "sqr using default single precision: time ";t3;" seconds","sum = ";s
t1=timer
asm
fstcw word ptr [oldcw]
fldcw word ptr [cwsingle] 'set FPU precision to single
end asm
for i as integer=1 to 3000
s=0
for j as integer=1 to 100000
s+=sqr(j)
next
next
asm
fldcw word ptr [oldcw] 'restore control word
end asm
t2=timer
t4=t2-t1
print "sqr using reduced single precision: time ";t4;" seconds","sum = ";s
print "reduced single precision sqr is ";t3/t4;" times faster"
end scope
print "=== double ==="
scope
dim as double x=3.141592653589793, y, z, s
t1=timer
for i as integer=1 to 3000
s=0
for j as integer=1 to 100000
s+=sqr(j)
next
next
t2=timer
t3=t2-t1
print "sqr using default double precision: time ";t3;" seconds","sum = ";s
t1=timer
asm
fstcw word ptr [oldcw]
fldcw word ptr [cwdouble] 'set FPU precision to double
end asm
for i as integer=1 to 3000
s=0
for j as integer=1 to 100000
s+=sqr(j)
next
next
asm
fldcw word ptr [oldcw] 'restore control word
end asm
t2=timer
t4=t2-t1
print "sqr using reduced double precision: time ";t4;" seconds","sum = ";s
print "reduced double precision sqr is ";t3/t4;" times faster"
end scope
sleep