Coder Social home page Coder Social logo

Comments (6)

EliSnow avatar EliSnow commented on September 13, 2024

Upon further examination this appears to be a difference between Benchmark.prototype.onStart and benchmark.events.start. Why the difference? I would assume that using onStart verses on("start",...) would net the same affect.

from benchmark.js.

jdalton avatar jdalton commented on September 13, 2024

Internally the benchmark is cloned to collect a sample of runs, by setting the Benchmark.options.onStart you're adding that as the default onStart for all benchmarks created (even the internal clones).

from benchmark.js.

EliSnow avatar EliSnow commented on September 13, 2024

While I understand what is going on internally with cloned benchmarks, the difference in behavior between benchmark.onStart and adding an event listener with benchmark.on("start", ...) seems unintuitive. The confusion arises because I am used to the DOM event model where DOMElement.onClick = ... and DOMElement.addEventListener("click", ... behave the same.

from benchmark.js.

jdalton avatar jdalton commented on September 13, 2024

Benchmark.options is the default options for all benchmarks created. The Benchmark constructor accepts an options object where onStart can be specified or later on the benchmark instance via myBench.on('start', ...).

from benchmark.js.

EliSnow avatar EliSnow commented on September 13, 2024

Thank you for the clarification. It seems onStart should never be directly set on a benchmark object. Correct me if I'm wrong @jdalton, but when a benchmark is cloned the original benchmark itself acts as the options object during the construction of the clone.

If I may ask one more rhetorical question, would it not make sense that clones created internally during run have their events cleared? I say this because benchmark.onStart benchmark.onCycle and benchmark.onComplete should accomplish everything needed.

from benchmark.js.

jdalton avatar jdalton commented on September 13, 2024

There is no mybench.onStart, or mybench.onCycle or mybench.onComplete. There are options properties for onStart, onCycle and the rest. The clones are created with their event listeners mandated to them.

from benchmark.js.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.