[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Speed differences fast and not fast


I am surprised at the difference in a simple for loop between fast and not fast

sample program follows and speeds printed after

' Gambas module file

Public Sub Main()

  Print "Hello world"
  slowly()
  quickly()

End

Public Sub slowly()
  Dim startt As Float = CFloat(Now)
  For i As Integer = 0 To 100000000
    If i % 50000000 = 0 Then Print i
  Next
  Print "slowly : "; (CFloat(Now) - startt) * 100000.00
End

Fast Unsafe Public Sub quickly()
  Dim startt As Float = CFloat(Now)
  For i As Integer = 0 To 100000000
    If i % 50000000 = 0 Then Print i
  Next
  Print "quickly : "; (CFloat(Now) - startt) * 100000.00
End

outputs the  following

Hello world
0
50000000
100000000
slowly : 13.7094873934984
0
50000000
100000000
quickly : 0.175926834344864

the difference is a lot larger than I thought  it was in the past.

Am I doing something wrong here?



Follow-Ups:
Re: Speed differences fast and not fastBruce Steers <bsteers4@xxxxxxxxx>