Skip to content

⚡️ Extract inlined-classes outside of Arbitrary base-class #1264

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

Merged
merged 1 commit into from
Dec 16, 2020

Conversation

dubzzz
Copy link
Owner

@dubzzz dubzzz commented Dec 16, 2020

In a nutshell

❌ New feature
❌ Fix an issue
❌ Documentation improvement
✔️ Other: performance

(✔️: yes, ❌: no)

Potential impacts

Arbitraries in general.

@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 65dbca1:

Sandbox Source
Vanilla Configuration
fast-check-examples Configuration

@dubzzz
Copy link
Owner Author

dubzzz commented Dec 16, 2020

Here are the stats I got from my local benchmark:

Reference..gen.integer x 4,372 ops/sec ±9.11% (179 runs sampled)
Test.......gen.integer x 4,462 ops/sec ±4.60% (176 runs sampled)
Reference..gen.integer:map x 838 ops/sec ±4.46% (152 runs sampled)
Test.......gen.integer:map x 3,778 ops/sec ±5.22% (178 runs sampled)
Reference..gen.integer:map:map x 506 ops/sec ±3.93% (152 runs sampled)
Test.......gen.integer:map:map x 3,012 ops/sec ±8.07% (162 runs sampled)
Reference..gen.integer:chain x 758 ops/sec ±4.58% (143 runs sampled)
Test.......gen.integer:chain x 3,205 ops/sec ±5.69% (165 runs sampled)
Reference..gen.integer:filter x 797 ops/sec ±4.30% (147 runs sampled)
Test.......gen.integer:filter x 4,002 ops/sec ±4.54% (175 runs sampled)
Reference..gen.integer:noShrink x 746 ops/sec ±3.47% (146 runs sampled)
Test.......gen.integer:noShrink x 3,859 ops/sec ±5.00% (173 runs sampled)
Reference..gen.integer:noBias x 2,810 ops/sec ±4.95% (148 runs sampled)
Test.......gen.integer:noBias x 4,709 ops/sec ±4.62% (179 runs sampled)
Reference..gen.float x 832 ops/sec ±4.29% (145 runs sampled)
Test.......gen.float x 3,738 ops/sec ±4.96% (172 runs sampled)
Reference..gen.floatNext x 838 ops/sec ±4.45% (155 runs sampled)
Test.......gen.floatNext x 3,465 ops/sec ±5.15% (169 runs sampled)
Reference..gen.double x 705 ops/sec ±3.98% (150 runs sampled)
Test.......gen.double x 2,528 ops/sec ±5.96% (169 runs sampled)
Reference..gen.doubleNext x 703 ops/sec ±4.93% (149 runs sampled)
Test.......gen.doubleNext x 2,743 ops/sec ±4.57% (170 runs sampled)

With node 12.18.2

Code of the benchmark
const Benchmark = require('benchmark');
const fcOld = require('../lib-old/fast-check');
const fcNew = require('../lib-new/fast-check');

const { runComplexFailure, runArraySuccess } = require('./tasks');

const MIN_SAMPLES = 100;
const benchConf = { minSamples: MIN_SAMPLES };
const sampler = (fc, arb) => fc.sample(arb);

const algos = [
  { name: 'gen.integer', run: (fc) => sampler(fc, fc.integer()) },
  {
    name: 'gen.integer:map',
    run: (fc) =>
      sampler(
        fc,
        fc.integer().map((i) => i)
      ),
  },
  {
    name: 'gen.integer:map:map',
    run: (fc) =>
      sampler(
        fc,
        fc
          .integer()
          .map((i) => i)
          .map((i) => i)
      ),
  },
  {
    name: 'gen.integer:chain',
    run: (fc) =>
      sampler(
        fc,
        fc.integer().chain((i) => fc.constant(i))
      ),
  },
  {
    name: 'gen.integer:filter',
    run: (fc) =>
      sampler(
        fc,
        fc.integer().filter(() => true)
      ),
  },
  {
    name: 'gen.integer:noShrink',
    run: (fc) => sampler(fc, fc.integer().noShrink()),
  },
  {
    name: 'gen.integer:noBias',
    run: (fc) => sampler(fc, fc.integer().noBias()),
  },
  { name: 'gen.float', run: (fc) => sampler(fc, fc.float()) },
  { name: 'gen.floatNext', run: (fc) => sampler(fc, fc.float({ next: true })) },
  { name: 'gen.double', run: (fc) => sampler(fc, fc.double()) },
  { name: 'gen.doubleNext', run: (fc) => sampler(fc, fc.double({ next: true })) },
];

for (const a of algos) {
  for (let idx = 0; idx !== 1000; ++idx) {}
  a.run(fcOld);
  a.run(fcNew);
}
for (const a of algos) {
  Benchmark.invoke(
    [
      new Benchmark(`Reference..${a.name}`, () => a.run(fcOld), benchConf),
      new Benchmark(`Test.......${a.name}`, () => a.run(fcNew), benchConf),
    ],
    {
      name: 'run',
      queued: true,
      onCycle: (event) => console.log(String(event.target)),
    }
  );
}

@coveralls
Copy link

Coverage Status

Coverage increased (+0.004%) to 96.872% when pulling 65dbca1 on perf-optim-map into 179bd89 on master.

@dubzzz dubzzz merged commit edf46f1 into master Dec 16, 2020
@dubzzz dubzzz deleted the perf-optim-map branch December 16, 2020 19:58
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

2 participants