location.href vs location.assign

JavaScript performance comparison

Revision 4 of this test case created by Mike McCaughan

Info

Added reset code to ensure navigation takes place.

Preparation code

<iframe id="test" src="about:blank"></iframe>
<script>
Benchmark.prototype.setup = function() {
    var frame = document.getElementById('test').contentWindow;
};

Benchmark.prototype.teardown = function() {
    document.getElementById('test').contentWindow.location.href = "about:blank";
};
</script>

Preparation code output

Test runner

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

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
location.href
frame.location.href = 'javascript:example=1';
pending…
location.assign
frame.location.assign('javascript:example=1');
pending…

Compare results of other browsers

Revisions

You can edit these tests or add even more tests to this page by appending /edit to the URL. Here’s a list of current revisions for this page:

0 comments

Add a comment