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

⚡️ Faster implementation for safeApply #3105

Merged
merged 3 commits into from
Aug 31, 2022
Merged

⚡️ Faster implementation for safeApply #3105

merged 3 commits into from
Aug 31, 2022

Conversation

dubzzz
Copy link
Owner

@dubzzz dubzzz commented Aug 31, 2022

Benchmark measurements made at https://github.com/dubzzz/fast-check-benchmarks/blob/main/benchmark-poisoning.js proved that the code for safeApply can be speed-up by huge factors if rewritten in a try/catch maner.

We measured:

  • before: from 15,083.692 to 15,573.392 ops/sec
  • after: from 59,929.287 to 61,058.436 ops/sec

On this benchmark. Figures need to be confirmed on fast-check's code but figures looks promising.

Category:

  • ✨ Introduce new features
  • 📝 Add or update documentation
  • ✅ Add or update tests
  • 🐛 Fix a bug
  • 🏷️ Add or update types
  • ⚡️ Improve performance
  • Other(s): ...

Potential impacts:

  • Generated values
  • Shrink values
  • Performance
  • Typings
  • Other(s): ...

Benchmark measurements made at https://github.com/dubzzz/fast-check-benchmarks/blob/main/benchmark-poisoning.js proved that the code for `safeApply` can be speed-up by huge factors if rewritten in a try/catch maner.

We measured:
- before: from 15,083.692 to 15,573.392 ops/sec
- after: from 59,929.287 to 61,058.436 ops/sec

On this benchmark. Figures need to be confirmed on fast-check's code but figures looks promising.
@codesandbox-ci
Copy link

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit c859872:

Sandbox Source
Vanilla Configuration
@fast-check/examples Configuration

@dubzzz
Copy link
Owner Author

dubzzz commented Aug 31, 2022

Performance measurements for current main 703e44e (aka main) vs 3.1.0 (aka 3.1.0) vs this PR (aka extra):

Algorithm;3.1.0;main;extra
Property(fc.boolean());7917.279147540943;6252.318870904624;7481.173579557897
Property(fc.integer());8163.074249478699;6315.610476040551;7333.181851970087
Property(fc.maxSafeInteger());7826.616859948053;6180.233237048319;7091.337498658444
Property(fc.float());7205.203739384096;5844.6331136854915;6719.037815263691
Property(fc.double());5782.097502156481;4766.14117584545;5265.844310444155
Property(fc.bigInt());2372.9469652584016;2136.955340217487;2300.0584357475486
Property(fc.char());7736.421568392434;6114.914375428913;7204.26733492436
Property(fc.string());3977.68522030364;2323.341411175722;3164.0436643969274
Property(fc.string({ minLength: 0, maxLength: 500, size: 'max' }));232.45307473504926;103.39477651048755;165.94100432322568
Property(fc.string({ minLength: 0, maxLength: 25_000, size: 'max' }));3.3875100009669468;1.5279155544327934;2.284735958718015
Property(fc.array(fc.integer()));5098.542523004534;2901.1845730973496;4114.493957005061
Property(fc.array(fc.integer(), { minLength: 0, maxLength: 500, size: 'max' }));345.46468599565986;121.27353194081556;219.22194273829535
Property(fc.array(fc.integer(), { minLength: 0, maxLength: 25_000, size: 'max' }));5.531042655643405;2.1059242188019507;3.720679893677901
Property(fc.uniqueArray(fc.integer()));4437.6904919571725;2422.1405205811575;3555.120062740557
Property(fc.uniqueArray(fc.integer(), { minLength: 0, maxLength: 500, size:'max' }));227.53298600331706;86.45095644620388;157.3988859508023
Property(fc.anything());463.6797720269283;278.598398998453;381.334798941529
Property(fc.constant('a'));8982.897008593705;6683.748543682545;8040.624463789228
Property(fc.constantFrom('a', 'b', 'c'));8962.268132947436;6683.676072964838;7895.986222143467
Property(fc.option(fc.integer()));7693.223301020014;5940.259654301729;6905.95167730726
Property(fc.oneof(fc.ascii(), fc.hexa()));7031.255217416853;5767.950657469249;6671.22578476122
Property(fc.oneof(fc.ascii()@w=1, fc.hexa()@w=2));7251.967225369344;5795.044467871113;6554.38716518404
Property(fc.tuple(fc.ascii(), fc.hexa()));6141.699681148109;3916.998030139911;5033.828085295106
Property(fc.record({ascii: fc.ascii(), hexa: fc.hexa()}));5386.92455107633;2748.398884389508;3523.364715819096
Property();4163.8416385344635;2686.30014399364;3499.0478720065585
Property();2413.970308385785;1604.5986307072455;1976.1985300217727
Property(fc.emailAddress());75.24337196254574;63.88773038503986;68.89093389712527
Property(fc.webUrl());136.48434665276253;119.23265415914312;127.12616723255243
Property(fc.integer().filter(() => true));8088.948560458691;6263.211406009339;7298.271904621557
Property(fc.integer().map(n => n));7958.602126844628;6027.417817692051;7183.780861616909
Property(fc.integer().chain(() => fc.integer()));7066.343013210037;5646.3677777906205;6446.41144200298
Property(fc.integer().noBias());8743.648216882391;6540.4092693062175;7807.336485734737
Property(fc.integer().noShrink());8338.673864895496;6292.88504405531;7347.692040968617
(results in ops/s)

More details at: https://github.com/dubzzz/fast-check-benchmarks/actions/runs/2960555414

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

Successfully merging this pull request may close these issues.

None yet

1 participant