How to profile Javascript now that JSPerf is down? [closed]
Asked Answered
O

5

115

As some of you probably noticed jsperf is down for some time. But I still need to profile my Javascripts. Is there any possibility to do comparison tests ideally without the help of an external software?

Overwrought answered 8/6, 2016 at 7:26 Comment(8)
You could use jsfiddle (or jsbin, plunker, codepen etc...) and benchmark.js altogether. Here is a template : jsfiddle.net/533hc71h. It won't compile all run results otherwise will work as jsperf.com does.Pederast
@Pederast this is a very useful link. Please post this as an answer +1 from meTreva
Sorry, I had to remove the software recommendation part of your question to make is salvageable.Whittier
Another -not offline- alternative to jsperf is jsben.chBath
perf.link is by far my favorite. Super clean, simple, and well designedBloodhound
jsperf.app seems to be a mirror made before 5/7/2015, likely after 3/26/2015.Cassirer
Some commits are being made at github.com/jsperf/jsperf.comCassirer
feel free to run your own copy now as they have made it available open source : github.com/jsperf/jsperf.com.. enjoy!Fluorite
P
76

jsperf is based on benchmarkjs so using an online code editor (like jsfiddle, jsbin, plunker etc...) and including benchmarkjs as a library will do.

The only feature you won't have will be the compiled results for each browsers. This is just a temporary alternative.

Here is a jsfiddle template : https://jsfiddle.net/533hc71h/

But since we don't really care about HTML nor CSS I found plunker more suitable. Coupled with systemjs you can then separate your code into multiple files.

Here is the template : https://plnkr.co/edit/pJg5LsiSNqlc6immmGsW


Update

You really should only use those solution as quick temporary solution. As said on the comments for optimal result you had better run it locally, nowadays you can get a webserver like express or else running in sec.


Rather than "trick" Stack Overflow into allowing posting of these links, let's actually include some helpful code:

function test1() {

}

function test2() {

}

var cycleResults = document.getElementById('cycleResults');
var result = document.getElementById('result');
var btn = document.getElementById('btn');

// BENCHMARK ====================
btn.onclick = function runTests() {

  btn.setAttribute('disable', true);
  cycleResults.innerHTML = '';
  result.textContent = 'Tests running...';

  var suite = new Benchmark.Suite;

  // add tests
  suite
    .add('test1', test1)
    .add('test2', test2)
    // add listeners
    .on('cycle', function(event) {
      var result = document.createElement('li');
      result.textContent = String(event.target);

      document.getElementById('cycleResults')
        .appendChild(result);
    })
    .on('complete', function() {
      result.textContent = 'Fastest is ' + this.filter('fastest').pluck('name');
      btn.setAttribute('disable', false);
    })
    // run async
    .run({
      'async': true
    });
};
<script src="https://cdnjs.cloudflare.com/ajax/libs/benchmark/1.0.0/benchmark.min.js"></script>
<ul id='cycleResults'>

</ul>
<div id="result">

</div>
<br>
<button id="btn">
Run Tests
</button>
Pederast answered 14/6, 2016 at 9:57 Comment(5)
Be very careful about running benchmarks in one of these common bin providers. I'm not sure about the others, but jsbin injects a lot of "magic" code inline to provide certain features, the most harmful in this case being infinite loop protection that may drastically skew your results, depending on how your tests are written. //no-protect comment disables that particular thing, but even then there are others. I don't believe it injects into your external dependencies though, so benchmark internals shouldn't be affected.Lapwing
@JayPhelps you'll still be able to compare tests since they should all be affected the same way. Now like I said this was a temporary solution.Pederast
Ghetolay, your plnkr.co link doesn't work. It shows: "Unable to connect to any application instances". :(Antiphrasis
This errors occurs sometimes on plnkr globally it's not specific to my plnkr link. Just try it again, right now it's working.Pederast
Improved a bit on the jsfiddle template, namely dynamically defined test functions, improved visual output via a table & named tests after function name, and test error feedback. jsfiddle.net/2e8fcuhb/2Eipper
D
147

I decided to build tool like this. First public beta is at https://jsbench.me

EDIT: 2020-07-12 - v1 released

Diarist answered 11/2, 2017 at 20:43 Comment(9)
@TranslucentCloud, thanks. I'm still working on it and using it, but until monthly testruns go above few thousands, I'm not investing too much time. Not that I personally miss any featureSalic
So much better than jsperf. Still, if it's OSS you've got yourself a contributor.Debt
probably will be sooner or later. The only reason it is not is that it started as learning project and I wanted to hide my ugly source code :)Salic
In the light of JSperf being (again) down and other sites shutting down, I just wanted to (re)confirm jsbench.me is going steady and I have no plans to shut it down. New major update, v1, was released few months ago. It runs about 14.000 tests monthly now. We surpassed AWS free tier for DynamoDB so for a few months I've been paying for this. Not much though. But a bit of optimization is on the way and some kind of monetization to keep the AWS bill down. Plan for this year is to opensource it too. Code is clean enough now :)Salic
Just discovered this tool today. It is a great alternative to jsPerf imho. Also I think this tool needs more exposure, give this answer an upvote, and a star on GitHub, I did so already.Haldes
This is not an alternative, this is a killer! DX is way better on this one. Thanks a lot! (Edit: the github is already there if anyone is looking for it github.com/psiho/jsbench-me)Alanis
This answer would be better if it showed an example of the service's use. Currently, this is essentially a link-only answer.Mishandle
@HereticMonkey, can you suggest what exactly to write? As an answer to a question I don't really know what to write more. All those services mentioned in answers fulfill exactly the same goal and do it in a very similar way and most (if not all) of them were inspired by JsPerf. I really don't see any better way to describe most of those suggestions other than 2 simple words: "JSperf alternative".Salic
I said exactly what to write; "an example of the service's use".Mishandle
P
76

jsperf is based on benchmarkjs so using an online code editor (like jsfiddle, jsbin, plunker etc...) and including benchmarkjs as a library will do.

The only feature you won't have will be the compiled results for each browsers. This is just a temporary alternative.

Here is a jsfiddle template : https://jsfiddle.net/533hc71h/

But since we don't really care about HTML nor CSS I found plunker more suitable. Coupled with systemjs you can then separate your code into multiple files.

Here is the template : https://plnkr.co/edit/pJg5LsiSNqlc6immmGsW


Update

You really should only use those solution as quick temporary solution. As said on the comments for optimal result you had better run it locally, nowadays you can get a webserver like express or else running in sec.


Rather than "trick" Stack Overflow into allowing posting of these links, let's actually include some helpful code:

function test1() {

}

function test2() {

}

var cycleResults = document.getElementById('cycleResults');
var result = document.getElementById('result');
var btn = document.getElementById('btn');

// BENCHMARK ====================
btn.onclick = function runTests() {

  btn.setAttribute('disable', true);
  cycleResults.innerHTML = '';
  result.textContent = 'Tests running...';

  var suite = new Benchmark.Suite;

  // add tests
  suite
    .add('test1', test1)
    .add('test2', test2)
    // add listeners
    .on('cycle', function(event) {
      var result = document.createElement('li');
      result.textContent = String(event.target);

      document.getElementById('cycleResults')
        .appendChild(result);
    })
    .on('complete', function() {
      result.textContent = 'Fastest is ' + this.filter('fastest').pluck('name');
      btn.setAttribute('disable', false);
    })
    // run async
    .run({
      'async': true
    });
};
<script src="https://cdnjs.cloudflare.com/ajax/libs/benchmark/1.0.0/benchmark.min.js"></script>
<ul id='cycleResults'>

</ul>
<div id="result">

</div>
<br>
<button id="btn">
Run Tests
</button>
Pederast answered 14/6, 2016 at 9:57 Comment(5)
Be very careful about running benchmarks in one of these common bin providers. I'm not sure about the others, but jsbin injects a lot of "magic" code inline to provide certain features, the most harmful in this case being infinite loop protection that may drastically skew your results, depending on how your tests are written. //no-protect comment disables that particular thing, but even then there are others. I don't believe it injects into your external dependencies though, so benchmark internals shouldn't be affected.Lapwing
@JayPhelps you'll still be able to compare tests since they should all be affected the same way. Now like I said this was a temporary solution.Pederast
Ghetolay, your plnkr.co link doesn't work. It shows: "Unable to connect to any application instances". :(Antiphrasis
This errors occurs sometimes on plnkr globally it's not specific to my plnkr link. Just try it again, right now it's working.Pederast
Improved a bit on the jsfiddle template, namely dynamically defined test functions, improved visual output via a table & named tests after function name, and test error feedback. jsfiddle.net/2e8fcuhb/2Eipper
R
26

There is also https://www.measurethat.net/ which allows you to create and run javascript benchmarks

Ritual answered 1/9, 2016 at 5:56 Comment(6)
Promising, but as of now there's no search and it requires an OAuth login (can't do a local password).Joshua
Yeah, I am working on improving it. There are opened issues for what you mentioned and I expect them to be addressed soon: github.com/thecoderok/MeasureThat.net/issues/52 github.com/thecoderok/MeasureThat.net/issues/37 github.com/thecoderok/MeasureThat.net/issues/47Ritual
@MikePost local accounts are now supported, try itRitual
I like the UI @Ritual ! And I did some useful stuff with it tonight, so thanks! I know it's in progress.. I had a number of errors tonight (Oh Snap), I suspect around what are valid names for test cases... But it's a nice tool.. FYI measurethat.net/Benchmarks/ShowResult/1516Inarch
I started to migrate all my jsperf snippets that are dead at the moment to measurethat. Thanks for the great effort.Extremism
This answer would be better if it showed an example of the service's use. Currently, this is essentially a link-only answer.Mishandle
Y
9

I have incidentally come to know http://jsbench.github.io/.

It clearly reminds of good ol' jsperf.

You can save your benchmark, share them and they keep track of per-browser performance.

Here is one I just made up: For loop benchmark

(As a side note, you can only save a benchmark if you have a github account.)

Yippie answered 7/10, 2016 at 11:1 Comment(2)
But it wants read and write access to all gists, if you want to save... Don't like that. Apart from that it appears to be quite useful. Although the graph looks buggy to me.Glutamine
I agree on all points. A weird thing is that mobile browser labels do not always specify the platform on which the test was run.Yippie
H
8

Even though jsperf is online, if you still want to look at alternatives, I found https://jsben.ch/ to be quite useful and well designed.

Hershey answered 4/1, 2017 at 23:45 Comment(1)
This answer would be better if it showed an example of the service's use. Currently, this is essentially a link-only answer.Mishandle

© 2022 - 2024 — McMap. All rights reserved.