KovtunV / NoStringEvaluating

Fast low memory consuming mathematical evaluation without endless string parsing! Parses string formula once and uses its object sequence in each evaluation. Moreover, provides user defined functions and variables.
MIT License
28 stars 10 forks source link

Some hints to improve the quality of the benchmark #10

Closed mariuszgromada closed 1 year ago

mariuszgromada commented 1 year ago

Hi,

Many thanks for the lib and the benchmark. mXparser does not fight strictly for the performance - the main focus is the functionality. Anyway it is a great comparison. Before running the benchmark always turn off all the smart rounding settings - especially the canonical option is very heavy.

Please see more here: https://mathparser.org/mxparser-tutorial/smart-rounding-settings/ And here: https://mathparser.org/mxparser-tutorial/efficient-calculations-in-loops/ And here: https://mathparser.org/mxparser-tutorial/expression-pre-compilation/

Best regards :-)

KovtunV commented 1 year ago

Hi @mariuszgromada thanks for noticing!

Yep, I've already used pre-compilation)

  protected void CalcMxParser(string formula)
  {
      var expression = CreateMxParser(formula);

      expression.calculate();

      for (var i = 0; i < N; i++)
      {
          expression.calculate();
      }
  }

Surprisingly in MathParser.org-mXparser I found interesting performance leak without smart route disabling:

for example:

version 5.0.6 | Formula1_MxParser | 225.4 ms version 5.0.7 | Formula1_MxParser | 672.1 ms version 5.2.0 | Formula1_MxParser | 694.5 ms

but when I disable routing:

mXparser.disableAlmostIntRounding();
mXparser.disableUlpRounding();
mXparser.disableCanonicalRounding();

version 5.2.0 | Formula1_MxParser | 182.8 ms

Will create MR and share the results later, thanks!

mariuszgromada commented 1 year ago

Great, congrats for the lib! :-)

5.0.7 if I remember correctly (but I am unsure) was a re-work on calculation steps register :-) Please take a look https://mathparser.org/mxparser-tutorial/calculation-steps-register/

KovtunV commented 1 year ago

Hi @mariuszgromada, I updated benchmark as you've written, now x8 faster, not x9 :)

I've added rounding disabling here Take a look please is benchmark correct?

mariuszgromada commented 1 year ago

Thanks! You motivated me to make some performance improvements. I have a sloppy loop statemented that is O(n) inside of O(n), finally I get O(n^2). This is why longer expressions are penalized more :-)

I will make some changes later :-)

KovtunV commented 1 year ago

Great to hear that! Raring to see the new version :)

mariuszgromada commented 1 year ago

So new version has just been published, can you test it now? :-) NuGet\Install-Package MathParser.org-mXparser -Version 5.2.1

KovtunV commented 1 year ago

Awesome! Will test a bit later :)

KovtunV commented 1 year ago

@mariuszgromada perfect results, now I'm only x4 faster! But mXparser became slower almost twice in formula9 (compared with previous version)

mariuszgromada commented 1 year ago

@KovtunV exactly, to improve performance more (especially for the IF function) I have to think a bit longer. But still I did quite significant improvement :-)

Your lib works great, congrats!

KovtunV commented 1 year ago

@mariuszgromada thank you) should I merge it into the master or wait for the next improvements?

mariuszgromada commented 1 year ago

Please merge :-)