|
-
Nov 21st, 2000, 03:33 AM
#1
Thread Starter
transcendental analytic
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:
Code:
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 
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
Nov 21st, 2000, 03:51 PM
#2
Hyperactive Member
mmm interesting 
problem is, in GL and D3D you need a bit of floating point, so you could run into speed probs if doing a lot.
vb really shouldn't let you use \ (int div) for something like 23.3 divided by 1203, or at least have a compiler option to disallow it, because as the test shows, it means slowdown, and you really should know the difference 
(although i only realised there were 2 div operators a few months ago)
buzzwords are the language of fools
-
Nov 21st, 2000, 06:51 PM
#3
Frenzied Member
The \ integer division operator was one of the first things I learnt when I was learning VB, surely it's common knowledge?
Harry.
"From one thing, know ten thousand things."
-
Nov 21st, 2000, 10:12 PM
#4
Frenzied Member
I did quite a few programming, and today when I read this posts, I first saw this!!
I always used the other one!! Good to know!
Cu
Sanity is a full time job
Puh das war harter Stoff!
-
Nov 21st, 2000, 10:21 PM
#5
Thread Starter
transcendental analytic
well i've seen this in some other languages never heard it in basic though, anyway as you see you can get quite optimized using both \ and / in different situations
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|