» 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!

Use "X 1" instead of "Cint(x)"

"X 1" is a lot faster, and the end result is the same. The speed increase is actually more than I would have expected. But as with many other optimizations, this test has been done with 500.000 iterations. So for small loops you might not notice it.

Code:
Public Sub TestOne() Dim lngReturn As Long lngReturn = CInt(100.543253) End Sub Public Sub TestTwo() Dim lngReturn As Long lngReturn = 100.543253 1 End Sub

CInt(x) % faster than x 1 CInt(x) (sec) x 1 (sec)
40,5% 0,035031 0,024938
17,7% 0,027812 0,023638
14% 0,026613 0,023351
43,8% 0,034486 0,023985
7,5% 0,026673 0,024821


User contributed notes:

Author: VBBR () Date: 22:03 31/03/2004
I think the idea here is to show the difference between CInt and x \ 1, right? But it says "x 1" instead of "x \ 1"...

Author: PRoPHEZZoR (prophezzor at hackermail dot com) Date: 14:04 04/04/2004
In PHP the \\ doesn't show, homie...

Author: Tom (hurendo_kun at hotmail dot com) Date: 15:06 08/06/2005
Your results are exacerbated because you're doing two type conversions. You should be using CLng().

Author: TheShau (shauros at walla dot com) Date: 14:08 04/08/2006
I'm seeing the same efficiency gain with CLng.

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