kedaman
Nov 21st, 2000, 02:33 AM
It has been posted on a thread that \ does integer division, forgot where the thread was... anyway somehow it seemed like it didn't operate as integer division should and was rejected, well i just checked it out, and \ really does integer division. The problem was that the nonintegers that was involved was of course converted to integers using Cint() not Int() as you didn't expect.
However i did some test with both operators and the first thought i had was a bit disappointed:
2670 ms for integer division
2515 ms for floating point division
Thats not much difference, and when i saw that in fact the integer division was slower, i got suspicious did some new tests:
Private Declare Function GetTickCount Lib "kernel32" () As Long
Sub test()
Dim start&, a&
start = GetTickCount
For x = 0 To 10000000
'Here's the buggy tests, what vb does is uses CINT function on 23.3
'which should take up a lot of cpu speed as you see.
'a = 23.3 \ 1203 ' 2660 ms
'a = 23.3 / 1203 ' 2450 ms
'The winner of the contest is of course simple integer division
'Try to avoid floating point division whenever possible
'a = 23 \ 1203 ' 1504 ms
'a = 23 / 1203 ' 2940 ms
'Same goes for declared variables, integers are faster than floating points
'somehow you see the difference at floating point division, it's slightly faster
'when you leave the long declaration.
'a = 23& \ 1203& ' 1504 ms
'a = 23& / 1203& ' 2970 ms
'As you see integer division is useless with floating points, especially when you
'convert them. Also you can gain something on declaring floating points for floating
'point division
'a = 23! \ 1203! ' 3730 ms
'a = 23! / 1203! ' 2870 ms
'Doubles gives you a strange difference in opposite direction for both integer and
'floating point division
'a = 23# \ 1203# ' 3700 ms
'a = 23# / 1203# ' 2890 ms
'smaller numbers doesn't operate faster, it seems like the smaller the result is, the
'faster it operates.
'a = 5& \ 2& ' 1523 ms
'a = 5& / 2& ' 3693 ms
'Using Int to convert isn't good. it's better than leaving VB to decide Cint to do it
'but if you need to divide floating points with integer division repeatedly you should
'store the converted values somewhere.
'a = Int(23.3) \ Int(1203) ' 3030 ms
Next x
Debug.Print GetTickCount - start
End Sub
phew that was very unusual of me, commenting that much. Well hope this helps you with
all speed critical issues :)
However i did some test with both operators and the first thought i had was a bit disappointed:
2670 ms for integer division
2515 ms for floating point division
Thats not much difference, and when i saw that in fact the integer division was slower, i got suspicious did some new tests:
Private Declare Function GetTickCount Lib "kernel32" () As Long
Sub test()
Dim start&, a&
start = GetTickCount
For x = 0 To 10000000
'Here's the buggy tests, what vb does is uses CINT function on 23.3
'which should take up a lot of cpu speed as you see.
'a = 23.3 \ 1203 ' 2660 ms
'a = 23.3 / 1203 ' 2450 ms
'The winner of the contest is of course simple integer division
'Try to avoid floating point division whenever possible
'a = 23 \ 1203 ' 1504 ms
'a = 23 / 1203 ' 2940 ms
'Same goes for declared variables, integers are faster than floating points
'somehow you see the difference at floating point division, it's slightly faster
'when you leave the long declaration.
'a = 23& \ 1203& ' 1504 ms
'a = 23& / 1203& ' 2970 ms
'As you see integer division is useless with floating points, especially when you
'convert them. Also you can gain something on declaring floating points for floating
'point division
'a = 23! \ 1203! ' 3730 ms
'a = 23! / 1203! ' 2870 ms
'Doubles gives you a strange difference in opposite direction for both integer and
'floating point division
'a = 23# \ 1203# ' 3700 ms
'a = 23# / 1203# ' 2890 ms
'smaller numbers doesn't operate faster, it seems like the smaller the result is, the
'faster it operates.
'a = 5& \ 2& ' 1523 ms
'a = 5& / 2& ' 3693 ms
'Using Int to convert isn't good. it's better than leaving VB to decide Cint to do it
'but if you need to divide floating points with integer division repeatedly you should
'store the converted values somewhere.
'a = Int(23.3) \ Int(1203) ' 3030 ms
Next x
Debug.Print GetTickCount - start
End Sub
phew that was very unusual of me, commenting that much. Well hope this helps you with
all speed critical issues :)