» Home » VB Fibre
Site
News
Files

Visual Basic
Strings
Math
General
Properties
Memory
Methods

Search
Testing

Inline ASM-VB
Strings
Math
General
Memory

Search
Using inline ASM
Submit!

Always use "\" instead of "/"

Major performance gain here! For integer calculations you should always use "" instead of "/" Using "" is faster because if you divide by "/" the values will first be converted to singles. So for Sin/Cos/Tan operation you should still use "/" if you want to have precision.

Code:
Public Sub TestOne() Dim intResult As Integer '//Floating point division intResult = 100 / 50 End Sub Public Sub TestTwo() Dim intResult As Integer '//Integer division intResult = 100 50 End Sub

100 / 50 % faster than 100 50 100 / 50 (sec) 100 50 (sec)
548% 0,045475 0,007018
568,2% 0,046955 0,007027
549,3% 0,046190 0,007114
589% 0,050495 0,007328
463,6% 0,045453 0,008064


User contributed notes:

Author: Cloral () Date: 22:04 16/04/2004
Once again, the \ needs to be fixed. \ is an escape character, so you need to do \\ for it to display one.

Author: Almar Joling () Date: 22:04 16/04/2004
I know, but for the moment I don't have the time to do so.

Author: Paul () Date: 10:05 19/05/2004
I've tried it and it seems \\ doesn't work for doubles.
10/3 gives 3.333333
10\\3 gives 3

Author: Almar Joling () Date: 10:05 19/05/2004
Yes, because it's an integer calculation with \. It will not return floating ponit values, hence why it's faster to use this for integer operations. :)

Author: Paddo Swam (paddoswam at gmail dot com) Date: 15:03 08/03/2005
the \\ is only to show it in the PHP code ;)

The vb code one should be \ and /

Author: Almar () Date: 19:03 08/03/2005
Exactly. :)

Author: TheShau (shauros at walla dot com) Date: 14:08 04/08/2006
Well, using "\" is one processor operation (div or idiv) not considering type casts, and "/" is a floating point operation which are much longer, of course.

Add user-note
Author:
E-mail (optional):
Anti spam, please enter 'ok' without quotes:
Comment: