Closed Bug 42309 Opened 24 years ago Closed 23 years ago

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

Categories

(Core :: JavaScript Engine, defect, P3)

defect

Tracking

()

VERIFIED WORKSFORME
Future

People

(Reporter: kazhik, Assigned: waldemar)

References

()

Details

(Keywords: perf)

Attachments

(3 files)

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.
Attached file Math.sqrt() Test
setting status to New
Status: UNCONFIRMED → NEW
Ever confirmed: true
Another test case.

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

This JavaScript does not use Math.sqrt(), but runs very slow.
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              




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.
Attached file Math.pow() test
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.
Attached file Math.abs() test
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
Status: NEW → ASSIGNED
Summary: Math.sqrt() runs very slow → Math.method()s run very slow [WAS: Math.sqrt() runs very slow]
Target Milestone: --- → Future
Keywords: perf
Mozilla became faster. This bug can be marked as worksforme.

Math.sqrt()
Moz: 451ms; IE: 171ms; NN4.7: 431ms
Per KOIKE's finding above, marking WORKSFORME - 
Status: ASSIGNED → RESOLVED
Closed: 23 years ago
Resolution: --- → WORKSFORME
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.

Attachment

General

Creator:
Created:
Updated:
Size: