On testing different methods for preventing default event handling, I made the comment that neither would meaningfully impact performance, and I'd like to back that up with cold, hard data.

Two options under consideration are:

Use an Attribute:

 <a href="https://stackoverflow.com/q/8614438/1366033" 
    onclick="event.preventDefault()" target="_blank">onclick attribute</a>

Use an Event Handler:

<a href="https://stackoverflow.com/q/8614438/1366033" target="_blank" >jQuery handler</a>
    $("body").on("click", "a", function(e) { e.preventDefault() });

Demo in jsFiddle

I wanted to use jsPerf to run through the two test cases. However, the test cases differ in the the HTML setup as well as the execution of JavaScript.

Is there a way to include different HTML in the jsPerf runner?

JS Perf Test Cases

  • 1
    Even though it's technically a web app, you probably want to ask this at Stack Overflow. I see over 50 questions tagged jsperf, and many of them seem of a similar bent.
    – ale
    Commented Nov 18, 2016 at 4:19


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.