killme2008 / defun

A macro to define clojure functions with parameter pattern matching just like erlang or elixir.
Eclipse Public License 1.0
477 stars 20 forks source link

Can the performance be improved? defun is 4x slower than defn. #17

Closed ghost closed 7 years ago

ghost commented 7 years ago

I ran the benchmark and similar to your results, the performance is not good enough. My test results:

Evaluation count : 92520 in 60 samples of 1542 calls.
      Execution time sample mean : 645.081223 µs
             Execution time mean : 645.082481 µs
Execution time sample std-deviation : 5.005565 µs
    Execution time std-deviation : 5.117810 µs
   Execution time lower quantile : 637.577837 µs ( 2.5%)
   Execution time upper quantile : 655.627332 µs (97.5%)
                   Overhead used : 9.233123 ns

Found 1 outliers in 60 samples (1.6667 %)
  low-severe   1 (1.6667 %)
 Variance from outliers : 1.6389 % Variance is slightly inflated by outliers

 Evaluation count : 20880 in 60 samples of 348 calls.
      Execution time sample mean : 2.919145 ms
             Execution time mean : 2.920135 ms
Execution time sample std-deviation : 40.550684 µs
    Execution time std-deviation : 41.397063 µs
   Execution time lower quantile : 2.879026 ms ( 2.5%)
   Execution time upper quantile : 2.964349 ms (97.5%)
                   Overhead used : 9.233123 ns

Found 4 outliers in 60 samples (6.6667 %)
  low-severe   1 (1.6667 %)
  low-mild   2 (3.3333 %)
  high-mild  1 (1.6667 %)
 Variance from outliers : 1.6389 % Variance is slightly inflated by outliers

As you can see defn takes 645.082481 µs whereas defun is taking 2.920135 ms (2920.135 µs), which is 4.5x slower. Love the library but I am not sure I can use it for any serious development. Please improve the performance.

killme2008 commented 7 years ago

hi, defun is just a thin wrapper on core.match, and the performance bottleneck is also on it.

We are using defun in our production with instaparse to implement a DSL, it works well. But you should balance the performance and expressive in your development by yourself.