Author Topic: The _HYPOT command  (Read 8043 times)

0 Members and 1 Guest are viewing this topic.

Offline TerryRitchie

  • Seasoned Forum Regular
  • Posts: 495
  • Semper Fidelis
    • View Profile
The _HYPOT command
« on: September 22, 2018, 10:57:25 pm »
When I run the test code below provided by Steve I get:

1.539 seconds for Hypot
1.367 seconds for Math stuff

_HYPOT should be faster, correct?

This is curious, change the first line to read:

_DEFINE A-Z AS INTEGER

I get:

2.000 seconds for Hypot
1.000 seconds for Math stuff

Now that's too perfect to be a coincidence?

Code: QB64: [Select]
  1.  
  2. t = TIMER
  3. FOR a = 1 TO 10000
  4.     FOR b = 1 TO 1000
  5.         c = _HYPOT(a, b)
  6.     NEXT
  7. t2 = TIMER
  8.  
  9. FOR a = 1 TO 10000
  10.     FOR b = 1 TO 1000
  11.         c = SQR(a ^ 2 + b ^ 2)
  12.     NEXT
  13. t3 = TIMER
  14.  
  15. PRINT USING "##.### seconds for Hypot"; t2 - t
  16. PRINT USING "##.### seconds for Math stuff"; t3 - t2
  17.  
In order to understand recursion, one must first understand recursion.

Offline TerryRitchie

  • Seasoned Forum Regular
  • Posts: 495
  • Semper Fidelis
    • View Profile
Re: The _HYPOT command
« Reply #1 on: September 22, 2018, 11:08:11 pm »
Change line 13 to read:

c = SQR(a * a + b * b)

I get the results:

1.594 seconds for Hypot
0.328 seconds for Math stuff

There is definitely something that needs looked at in the _HYPOT source code.
« Last Edit: September 22, 2018, 11:09:15 pm by TerryRitchie »
In order to understand recursion, one must first understand recursion.

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: The _HYPOT command
« Reply #2 on: September 22, 2018, 11:08:58 pm »
What version of QB64?  I get much different times than those.  O_o!
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline TerryRitchie

  • Seasoned Forum Regular
  • Posts: 495
  • Semper Fidelis
    • View Profile
Re: The _HYPOT command
« Reply #3 on: September 22, 2018, 11:12:23 pm »
Version 1.2 Revision 20180202/85 from git 1d0f920
In order to understand recursion, one must first understand recursion.

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: The _HYPOT command
« Reply #4 on: September 22, 2018, 11:13:52 pm »
Screenshot below.  Hypot is much quicker on my machine -- almost to the point of your numbers being reversed compared to mine.
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline TerryRitchie

  • Seasoned Forum Regular
  • Posts: 495
  • Semper Fidelis
    • View Profile
Re: The _HYPOT command
« Reply #5 on: September 22, 2018, 11:15:49 pm »
Yeah, that's spooky, the same 1.594 in opposite spots?
In order to understand recursion, one must first understand recursion.

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: The _HYPOT command
« Reply #6 on: September 22, 2018, 11:17:41 pm »
Difference is between QB64x32 and QB64x64.   I normally program in the 64-bit version of QB64, which is what the screenshot above is for.  Here's an image taken of the same code, same machine, with 32-bit QB64:

*********************
*********************

Hypot is faster in both cases, on my machine, but it's quite a bit slower with the 32-bit version.
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline TerryRitchie

  • Seasoned Forum Regular
  • Posts: 495
  • Semper Fidelis
    • View Profile
Re: The _HYPOT command
« Reply #7 on: September 22, 2018, 11:20:28 pm »
Why are my numbers so far off then? Is it the version of 32bit QB64 I'm using?
In order to understand recursion, one must first understand recursion.

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: The _HYPOT command
« Reply #8 on: September 22, 2018, 11:28:56 pm »
Why are my numbers so far off then? Is it the version of 32bit QB64 I'm using?

No idea.  I'm curious as heck now to see what results some other folks will generate with the same code.  I've always had _HYPOT run much faster on my machine, and I *assumed* it behaved the same for all others.   Let's wait and see how the speed tests turn out for a few other folks.  ;)
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline TerryRitchie

  • Seasoned Forum Regular
  • Posts: 495
  • Semper Fidelis
    • View Profile
Re: The _HYPOT command
« Reply #9 on: September 22, 2018, 11:30:24 pm »
Sounds good.
In order to understand recursion, one must first understand recursion.

Offline TerryRitchie

  • Seasoned Forum Regular
  • Posts: 495
  • Semper Fidelis
    • View Profile
Re: The _HYPOT command
« Reply #10 on: September 23, 2018, 12:15:16 am »
I just downloaded the latest build and ran the code.  Version 1.2 dev build from git e490b1a

1.593 seconds for Hypot
1.429 seconds for Math stuff
In order to understand recursion, one must first understand recursion.

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: The _HYPOT command
« Reply #11 on: September 23, 2018, 12:19:33 am »
If you don't mind, try this version and see what your times are:  https://www.dropbox.com/s/f2ec7twbbhvg33v/QB64%20x64%20%2807-21-2018%29.7z?dl=1

It's the 64-bit version of QB64, and much faster with _HYPOT for me.
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

FellippeHeitor

  • Guest
Re: The _HYPOT command
« Reply #12 on: September 23, 2018, 12:25:07 am »
macOS (64bit, bare metal):
    0.275 s _HYPOT
    1.703 s Math stuff

Ubuntu (virtual machine) 64bit:
    0.494 s _HYPOT
    1.978 s Math stuff

Windows XP (virtual machine) 32bit:
    2.088 s _HYPOT
    1.813 s Math stuff

Offline TerryRitchie

  • Seasoned Forum Regular
  • Posts: 495
  • Semper Fidelis
    • View Profile
Re: The _HYPOT command
« Reply #13 on: September 23, 2018, 12:31:18 am »
If you don't mind, try this version and see what your times are:  https://www.dropbox.com/s/f2ec7twbbhvg33v/QB64%20x64%20%2807-21-2018%29.7z?dl=1

It's the 64-bit version of QB64, and much faster with _HYPOT for me.

WOW!

0.220 seconds for Hypot
1.484 seconds for Math stuff

When I change line 13 to:

 c = SQR(a * a + b * b)

0.275 seconds for Hypot
0.165 seconds for Math stuff
In order to understand recursion, one must first understand recursion.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: The _HYPOT command
« Reply #14 on: September 23, 2018, 01:11:20 am »
Nice find Terry! I got nearly same results as Steve with ^2's but WOW! with a*a + b*b
« Last Edit: September 23, 2018, 01:12:23 am by bplus »