Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsVB SyntaxEnterprise DevelopmentDatabase AccessControlsCOMWin APICrystal ReportDeploymentGeneralGeneral 2
Related Topics
VB.NET / ASP.NETMS SQL ServerMS AccessOther Database ProductsMore Topics ...

VB Forum / General 2 / May 2008



Tip: Looking for answers? Try searching our database.

Need for Speed

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Stan Weiss - 21 May 2008 16:19 GMT
Is there any difference in speed between these 2 methods?

In .BAS Module
Global Const MPH_TO_FPS = 5280 / 3600     'Convert MPH to Feet per
Second
In .FRM File
ans14 = MPH1 * MPH_TO_FPS  'Vel. (ft/sec)

and
ans14 = MPH1 * 5280 / 3600  'Vel. (ft/sec)
Jim Mack - 21 May 2008 16:53 GMT
> Is there any difference in speed between these 2 methods?
>
> In .BAS Module
> Global Const MPH_TO_FPS = 5280 / 3600
   'Convert MPH to Feet per Second
> In .FRM File
> ans14 = MPH1 * MPH_TO_FPS  'Vel. (ft/sec)
>
> and
> ans14 = MPH1 * 5280 / 3600  'Vel. (ft/sec)

If you only do it once, then it hardly matters. If you do it
repeatedly then the first is better because it involves only one FP
operation.

BUT: if you haven't typed the variables and constants, then you'll get
Variants, so wondering about speed is pointless. (-:

If you're using Singles, then type everything as such:

Global Const MPH_TO_FPS As Single = 5280 / 3600

 ..
 ..

Dim ans14 As Single
Dim MPH1 As Single

ans14 = MPH1 * MPH_TO_FPS

--
   Jim Mack
   MicroDexterity Inc
   www.microdexterity.com
Stan Weiss - 21 May 2008 17:11 GMT
> > Is there any difference in speed between these 2 methods?
> >
[quoted text clipped - 30 lines]
>     MicroDexterity Inc
>     www.microdexterity.com

Thanks this will be in a loop and these are defined as
Dim ans14 As Double
Dim MPH1 As Double
Jim Mack - 21 May 2008 17:14 GMT
>> Jim Mack wrote:
>
[quoted text clipped - 13 lines]
> Dim ans14 As Double
> Dim MPH1 As Double

Then type the constant as Double too. But you will get better speed
using all Singles if you don't need the extra precision -- and almost
nothing that models the real world (like MPH) requires Doubles.

--
   Jim Mack
   MicroDexterity Inc
   www.microdexterity.com
Stan Weiss - 21 May 2008 17:34 GMT
> >> Jim Mack wrote:
> >
[quoted text clipped - 22 lines]
>     MicroDexterity Inc
>     www.microdexterity.com

The reason for using double is the customer wants to see 12 decimal
places.
Thanks Again,
Stan
Steve Gerrard - 22 May 2008 06:57 GMT
>> Then type the constant as Double too. But you will get better speed
>> using all Singles if you don't need the extra precision -- and almost
>> nothing that models the real world (like MPH) requires Doubles.
>
> The reason for using double is the customer wants to see 12 decimal
> places.

Because every 0.00000000528 of a foot per hour helps!  ;-)
Stan Weiss - 22 May 2008 16:01 GMT
> >> Then type the constant as Double too. But you will get better speed
> >> using all Singles if you don't need the extra precision -- and almost
[quoted text clipped - 4 lines]
>
> Because every 0.00000000528 of a foot per hour helps!  ;-)

No that was just an example. For the CONST use.

This is real output where because of the wrist pin offset velocity is
not zero at 180 degrees and he wants to know at what degree velocity is
zero to 12 decimal.

Bore = 4.0   Stroke = 3.25   Rod Length = 5.7   RPM = 6500
Wrist Pin Offset = 0.01
Maximum Piston Velocity 5754.922719 FPM @ 75.078416256241 Degrees

                        Piston              Piston
Crank Angle             Velocity          Acceleration
  Degree                FT/Sec            FT/Sec/Sec
179.85900000000     0.000456276916   -44854.925521303500
179.85910000000     0.000341264287   -44854.925356947700
179.85920000000     0.000226251658   -44854.925192605500
179.85930000000     0.000111239030   -44854.925028276700
179.85940000000    -0.000003773598   -44854.924863961600
179.85950000000    -0.000118786226   -44854.924699659900
179.85960000000    -0.000233798853   -44854.924535371800
179.85970000000    -0.000348811480   -44854.924371097300
179.85980000000    -0.000463824106   -44854.924206836300
179.85990000000    -0.000578836732   -44854.924042588800
Mike Williams - 22 May 2008 07:29 GMT
> The reason for using double is the customer
> wants to see 12 decimal places.

Have you asked him why?

Mike
Stan Weiss - 22 May 2008 18:26 GMT
Is there any difference in speed between these 2 methods?

In .BAS Module
Global ans1 As Double
Global ans10 As Double
Global ans14 As Double
Global Const DEG_TO_RAD As Double = kPI / 180#     'Convert Degrees to
RAD's

--- First Method
In .FRM File in a Loop
ans14 = ans1 * DEG_TO_RAD

--- Second Method
In .FRM File
ans10 = kPI / 180#

In .FRM File in a Loop
ans14 = ans1 * ans10
Auric__ - 22 May 2008 19:48 GMT
> Is there any difference in speed between these 2 methods?
>
[quoted text clipped - 15 lines]
> In .FRM File in a Loop
> ans14 = ans1 * ans10

Any time you can use a constant number, it's *always* faster to just use
the constant than to recalculate the number each time.

In this particular case, the first method calculates DEG_TO_RAD once, at
compile time, while the second method calculates it each time "ans10 =
kPI / 180#" is hit. If that line only happens once during the program
then the time hit is probably not noticeable (by humans, anyway)... but
if you already have DEG_TO_RAD declared anyway, why not just use it?

Signature

Where did you get this 60Hz ground hum you call brain activity?

 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2010 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.