spread-vs-explicit-object-shape

JavaScript performance comparison

Test case created by zerobias

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  const source = (Math.random() > 0.5) ? {
    status: 'done',
    params: {},
    result: 1
  } : {
    status: 'fail',
    params: null,
    error: Error('fail')
  }
  let result
  function spread(source) {
    return {...source, strategy: 'something'}
  }
  function assign(source) {
    return Object.assign({}, source, {strategy: 'something'})
  }
  function explicitObject(source) {
    return source.status === 'done'
    ? {
      status: source.status,
      params: source.params,
      result: source.result,
      strategy: 'something'
    }
    : {
      status: source.status,
      params: source.params,
      error: source.error,
      strategy: 'something'
    }
  }

};
</script>

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in CCBot 2.0.0 / Other 0.0.0
Test Ops/sec
spread
result = spread(source)
pending…
explicit shape
result = explicitObject(source)
pending…
assign
result = assign(source)
pending…

You can edit these tests or add even more tests to this page by appending /edit to the URL.

0 Comments