Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chapter Compiler Backend: Monomorphic/Polymorphic pattern benchmarks look strange/possibly wrong #3652

Open
sidkshatriya opened this issue Nov 30, 2022 · 1 comment

Comments

@sidkshatriya
Copy link

sidkshatriya commented Nov 30, 2022

In https://dev.realworldocaml.org/compiler-backend.html we have the following results (text reproduced as-is from rwo chapter):

dune exec -- ./bench_patterns.exe -ascii -quota 0.25
Estimated testing time 750ms (3 benchmarks x 250ms). Change using '-quota'.

  Name                        Time/Run   Percentage
 --------------------------- ---------- ------------
  Monomorphic large pattern     6.54ns       67.89%
  Monomorphic small pattern     9.63ns      100.00%
  Polymorphic large pattern     9.63ns       99.97%

According to these results:

  • The monomorphic large pattern ( type t = | Alice | Bob | Charlie | David is the fastest pattern).
  • Next fastest is the Polymorphic large pattern ( type t = | `Alice | `Bob | `Charlie | `David ) (See percentage to confirm)
  • Slowest is the Monomorphic small pattern ( type t = | Alice | Bob ).

This is contrary to what is expressed in the text of the book:

These results confirm the performance hypothesis that we obtained earlier by inspecting the lambda code. The shortest running time comes from the small conditional pattern match, and polymorphic variant pattern matching is the slowest. There isn’t a hugely significant difference in these examples, but you can use the same techniques to peer into the innards of your own source code and narrow down any performance hotspots.

@rand00
Copy link

rand00 commented Mar 10, 2023

+1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants