mathics / Mathics

This repository is for archival. Please see https://github.com/Mathics3/mathics-core
https://mathics.org
Other
2.08k stars 208 forks source link

Basic calculator list slowness #1568

Open rocky opened 2 years ago

rocky commented 2 years ago

Wny are we so slow on:

?

python ./mathics_benchmark/bench.py  -v ./benchmarks/calculator-fns.yaml
Mathics git repo /src/external-vcs/github/Mathics3/mathics-benchmark/Mathics at 58dc69
500 iterations of Plus...
  0.104490 secs for: 1 + 2                                   
  0.113165 secs for: 1 + 2 + 3                               
  0.258577 secs for: 1 + 2 + b                               
  0.176744 secs for: a + b + 3                               
  0.102528 secs for: 1234567890 + 2345678901                 
  17.513644 secs for: a + b + 4.5 + a                         

500 iterations of Times...
  0.104240 secs for: 1 * 2                                   
  0.114249 secs for: 1 * 2 * 3                               
  0.255315 secs for: 1 * 2 * b                               
  0.168563 secs for: a * b * 3                               
  0.104529 secs for: 1234567890 * 2345678901                 
  17.170605 secs for: a * b * 4.5 * a                         

500 iterations of Divide...
  0.270426 secs for: 1 / 2                                   
  0.440225 secs for: 1 / 2 / 3                               
  0.861948 secs for: 1 / 2 / b                               
  0.583282 secs for: a / b / 3                               
  0.277900 secs for: 1234567890 / 2345678901                 
  11.588511 secs for: a / b / 4.5                             

500 iterations of Power...
  0.115591 secs for: 1 ^ 2                                   
  0.232032 secs for: 1 ^ 2 ^ 3                               
  0.329244 secs for: 1 ^ 2 ^ b                               
  0.613662 secs for: a ^ b ^ 3                               
  0.145898 secs for: 12345 ^ 23456                           
  8.794525 secs for: a ^ b ^ 4.5 ^ a                         

500 iterations of Sqrt...
  0.536396 secs for: Sqrt[2]                                 
  0.586085 secs for: Sqrt[Sqrt[2], 3]                        
  0.587919 secs for: Sqrt[Sqrt[2], b]                        
  0.633341 secs for: Sqrt[Sqrt[Sqrt[2], b], 3]               
  0.939225 secs for: Sqrt[1234567890]         
rocky commented 2 years ago

Looks like the root cause again is the slowness in pattern matching, method look ups.

Download the zip file and unzip it. adds.zip

Give the .prof file as an argument to snakeviz, e.g. snakeviz cslow-add.prof. The corresponding Python file e.g. cslow-add.py will recreate the corresponding .prof file.