Google Analytics protocol check versus hardcoded string
JavaScript performance comparison
Info
The snippets I’m comparing here aren’t quite the same, but for HTTP-only websites it doesn’t make a difference. See the “Use the protocol check only when it’s needed” section in my article on optimizing the asynchronous Google Analytics snippet for more information.
Preparation code
<script>
Benchmark.prototype.setup = function() {
var location = window.location;
};
</script>
Test runner
Warning! For accurate results, please disable Firebug before running the tests. (Why?)
Java applet disabled.
| Test | Ops/sec | |
|---|---|---|
Ternary protocol check |
|
pending… |
Hardcoded string |
|
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:
- Revision 1: published by Mathias Bynens and last updated
- Revision 2: published by John-David Dalton
- Revision 3: published
2 comments
result quite astonishing!
Millions of ops/sec vs. millions of ops/sec for something that is executed 1 time means there is no real world perf concern here. Also the test with a simple string literal might be being optimized away as dead code.