Run jsperf tests in a bunch of WebPagetest browsers

Motivation

1. You write a new test to confirm a JavaScript-related performance speculation
2. You click
3. Your test runs in a bunch of browsers

Glossary

JSperf.com is the site where all you JavaScript performance guesswork should go to die or be confirmed. You know how the old wise people say "JSperf URL or it didn't happen! Now off my lawn!". Yup, that jsperf.com

WebPagetest.org (WPT) is the site where you get answers to the ol' question: "Why do people say my oowsome site is slow? And what should I do about it?"

Bookmarklet is a little piece of JavaScript you conveniently access from your browser bookmarks and inject into other non-suspecting sites.

Github is where you host code.

Bookmaker tool makes a bookmarklet from a .js file URL (probably hosted on github)

Trouble in paradise

These days we're so happy and spoiled with all these amazing tools around us. And yet, when you create a JSPerf test, you have to open all these browsers and run the test everywhere. Even IE. And, when on Mac, IE is usually not readily available. Plus it comes in a bunch versions - from almost-but-not-quite-forgotten IE6, all the way to IE10 The Greatest - and they have different, sometimes contradicting, performance characterics.

To the rescue: WPT

WebPagetest has: a/ ability to run in a bunch of browsers and b/ an API

The bookmarklet

The bookmarklet. It's here, on github

It starts by inquiring about your WPT API key. I know, you have to get one. You can read the API docs on how to get one, but let me save you the trip: you just need to ask pmeenan@[the tool's domain].org for a key. Politely. Tell him I sent you. Promise not to abuse.

  var key = localStorage.wpt_key;
  if (!key) {
    var prompt = window.__proto__.prompt;
    key = prompt('Your WebPageTest API key, please?');
    if (!key) {
      return gameOver();
    }
    localStorage.wpt_key = key;
  }

The key is stored in your localStorage so you don't have to paste it all the time.

Oh, you may wonder what's up with that:

var prompt = window.__proto__.prompt;
prompt('Message...');

Looks like something somewhere on jsperf is doing window.prompt = function(){}, same for window.open and probably others. Makes sense, you don't want popup-y stuff (by the thousands) while running a test a gazilion times. So the bookmarklet has to go the window.__proto__ for the original prompt

Moving on.

Setting up the constant params of the API call. The variable param will be the location which will tell what browser to use. We also give the (undocumented) time a value of 60s, so that the test has time to run. We also want only one run and just the first run (no full cache run).

The URL to test will be the current page loaded in jsperf.com which is where you run the bookmarklet. And we'll append #run for autorun.

  // base params
  var wpt = 'http://www.webpagetest.org/runtest.php?';
  var params = {
    k: key,
    time: 60,
    runs: 1,
    fvonly: 1,
    url: 'http://jsperf.com' + location.pathname + '#run'
  };
  Object
    .keys(params)
    .forEach(function(key) {
      wpt += key + '=' + encodeURIComponent(params[key]) + '&';
    });

Finally, setup the locations with browsers IE6,7,8,9,10 and open all these browser windows:

  var locations = localStorage.wpt_locations;
  if (!locations) {
    locations = ['Dulles_IE6', 'Dulles_IE7', 'Dulles_IE8', 'Dulles_IE9', 'Dulles_IE10'];
  }
  
  // pop some windows up
  var open = window.__proto__.open;
  locations.forEach(function(loco){
    open(wpt + 'location=' + encodeURIComponent(loco));
  });

Again, the full source is here on github

Github has a "raw" version, e.g. this so we take this url, paste it in the bookmaker tool and we get a nice installable bookmarklet link.

Install

Drag this link to you bookmarks:

jsperf -> wpt

Run

1. Go to any jsperf test, e.g. http://jsperf.com/array-proto-vs/3
2. Click the bookmarklet
3. Observe 5 new tabs with 5 IE versions running your test!

jsperf

More browsers

In addition to the browsers (locations) I've defined you can always add more, like Chrome and Firefox. However you probably have these already handy so no need to kill WPT's servers. But the option is there, just edit your localStorage.wpt_locations

Thanks for reading! Comments welcome!

This entry was posted on Monday, February 11th, 2013 and is filed under JavaScript, performance. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.


Get notification for future posts: follow me on Twitter or subscribe to my RSS feed

12 Responses to “Run jsperf tests in a bunch of WebPagetest browsers”

  1. Rick Viscomi Says:

    I really like this idea. It would be cool if jsperf had the ability to internally spin up a browser and measure the performance, but this is a great self-sufficient workaround.

    Stoyan, why not set each test with multiple (3) runs? Wouldn’t it be more accurate, in theory? Then again it would be taxing on the WPT machines.

  2. Marcel Duran Says:

    Good Job Stoyan! Once I had the idea of a jsperf-swarm where a swarm of different browsers are always up checking for new/untested jsperf tests then testing accordingly, therefore achieving several browsers test coverage for all jsperf tests ;-)

  3. ceny stron internetowych Says:

    Hello There. I discovered your weblog using msn. This is an extremely smartly written article.

    I’ll be sure to bookmark it and come back to read extra of your helpful information. Thanks for the post. I’ll definitely return.

    Here is my page: ceny stron internetowych

  4. Vincent Says:

    Nice idea, careful thought because WPT machines are low on performance.

    Little CPU, little RAM, old computer. IE7 Paris is a Dell which is 7 years old.

    Basically you could get an IE6 in Dulles that outperforms my IE7.

    So be carefull :-)

  5. Vincent Says:

    Saw that you are only using Dulles locations, as long as they use similar hardware, you’re good

  6. Appenrerham Says:

    Hello! I just would like to give a huge thumbs up for the amazing info you’ve here on this post. I might be coming back to your blog for more soon.

    [url=http://cheapsredsoleshoesa.fast-page.org]red bottom sandals[/url]

    http://outletschristianlouboutinsa.0fees.net

  7. Andre Says:

    “Dulles_Chrome”(localStorage.wpt_locations) became “Invalid Location” when I set locations as :
    locations = ['Dulles_Chrome', 'Dulles_Firefox', 'Dulles_Safari', 'Dulles_iPhone4 iOS 5.1', 'Dulles_NexusS Android 2.3'];

  8. ten link Says:

    Hi to every one, it’s genuinely a pleasant for me to go to see this web page, it consists of important Information.

  9. Funny Pics Says:

    Quite a great post it made me smile. I pay a visit to this web site
    on a daily basis since it’s definitely enormously funny.

  10. free hack money games Says:

    Having read this I believed it was extremely informative.

    I appreciate you taking the time and energy to put this informative article together.
    I once again find myself personally spending way too much time both reading and commenting.

    But so what, it was still worthwhile!

  11. Ashely Says:

    Hey there! I know this is kind of off-topic but I had to
    ask. Does managing a well-established blog such as yours require
    a large amount of work? I’m completely new to blogging but I do write in my journal every day. I’d like to start a blog so
    I will be able to share my own experience and thoughts online.

    Please let me know if you have any suggestions or tips
    for brand new aspiring bloggers. Thankyou!

  12. best gold 401k investment guide Says:

    My brother recommended I may like this blog. He was
    totally right. This post truly made my day. You cann’t consider simply how much time I had spent for this information! Thanks!

Leave a Reply