Math.method()s run very slow [WAS: Math.sqrt() runs very slow]

VERIFIED WORKSFORME

Status

()

Core
JavaScript Engine
P3
normal
VERIFIED WORKSFORME
18 years ago
16 years ago

People

(Reporter: Koike Kazuhiko, Assigned: Waldemar Horwat)

Tracking

({perf})

Trunk
Future
Points:
---

Firefox Tracking Flags

(Not tracked)

Details

(URL)

Attachments

(3 attachments)

(Reporter)

Description

18 years ago
Math.sqrt() seems to run very slow. See the sample page.

http://www5a.biglobe.ne.jp/~terucco/bz/xeyes.html

The eyeballs doesn't move when I accessed this page by old PC
(Pentium 166Mhz). 

The following attachment shows Math.sqrt() causes a problem.
(Reporter)

Comment 1

18 years ago
Created attachment 10021 [details]
Math.sqrt() Test

Comment 2

18 years ago
setting status to New
Status: UNCONFIRMED → NEW
Ever confirmed: true
(Reporter)

Comment 3

18 years ago
Another test case.

http://www5a.biglobe.ne.jp/~terucco/bz/ants211/index.html

This JavaScript does not use Math.sqrt(), but runs very slow.

Comment 4

18 years ago
Here are some timing results using the attachment above. 
Using a Mozilla tip build 06/27/2000 on WinNT.
 
Attachment = http://bugzilla.mozilla.org/showattachment.cgi?attach_id=10021
All times in milliseconds. The test loops have 50000 iterations.


           loop that is empty       loop of Math.sqrt(2)

IE4               31                        187
NN4.7             62                        421
Moz               78                        9812              




Comment 5

18 years ago
I've found that Math.pow() is _very_ slow compared to Navigator 4.73 and IE5.01, 
so maybe it's the Math() object in general and not simply Math.sqrt()?  I'll 
upload a simple testcase which squares a number 'd'.  d's a small number (122), 
the number of iterations is 100,000, which should take around 130ms in Mozilla. 
 Still, the job takes ~8000ms to complete using Math.pow(), 220ms using d*d.

in comparison IE5.01 uses ~550ms with Math.pow(), ~170ms using d*d, and NN4.73 
~1800ms with Math.pow(), ~220ms with d*d.

I'll do some more testing with the various other Math() methods and see what I 
find.

Comment 6

18 years ago
Created attachment 11031 [details]
Math.pow() test

Comment 7

18 years ago
Ack, forgot to mention that I'm running build 2000070508, Windows 98 first 
edition.  Also added myself to the Cc:-list.

Made a quick test using Math.abs(), and the result is the same as for 
Math.sqrt() and Math.pow().  This time I used Math.abs() for one loop and '(x < 
0) ? -x : x' in the other.  The loop with Math.abs() takes ~8000ms compared to 
~220ms for the other.

Speed for the two others is just about the same: ~1700ms & ~220ms for NN4.73, 
and ~500ms & ~160ms for IE5.01.

Will upload the Math.abs() testcase too.

Comment 8

18 years ago
Created attachment 11032 [details]
Math.abs() test

Comment 9

18 years ago
I have discussed this with the engineers on the JavaScript Engine team.

The reason for the performance problem may be due to the fact that JS 1.5 
(used in Mozilla, but not in NN 4.x) uses a library called "libfdm" 
to do math operations. This is done to ensure accuracy across all platforms,
but will of course be slower than utilizing native OS math processing. 

The team has asked me to send this one to Waldemar for his opinion - 
Assignee: rogerl → waldemar

Updated

18 years ago
Status: NEW → ASSIGNED

Updated

18 years ago
Summary: Math.sqrt() runs very slow → Math.method()s run very slow [WAS: Math.sqrt() runs very slow]
(Assignee)

Updated

18 years ago
Target Milestone: --- → Future

Updated

17 years ago
Keywords: perf

Comment 10

17 years ago
Mozilla became faster. This bug can be marked as worksforme.

Math.sqrt()
Moz: 451ms; IE: 171ms; NN4.7: 431ms

Comment 11

17 years ago
Per KOIKE's finding above, marking WORKSFORME - 
Status: ASSIGNED → RESOLVED
Last Resolved: 17 years ago
Resolution: --- → WORKSFORME

Comment 12

17 years ago
VERIFIED WORKSFORME using nightly binaries 20010312xx on WinNT, Linux, and Mac.
These are the timings I got from the testcase at attachment 10021 [details] above.
In each case Mozilla is running an empty loop, then a loop of Math.sqrt(2).


                         WINNT       LINUX        MAC
Empty loop:              47ms        45ms         31ms
Loop of Math.sqrt(2):    391ms       480ms        370ms



These are much better than the results from 2000-06-28 17:17 above: 

Empty loop:              78ms
Loop of Math.sqrt(2):    9812ms 

Status: RESOLVED → VERIFIED
You need to log in before you can comment on or make changes to this bug.