Questions tagged [jsperf]

JavaScript performance playground

jsPerf aims to provide an easy way to create and share test cases, comparing the performance of different JavaScript snippets by running benchmarks. For more information, see the FAQ on jsperf.com.

65 questions
166
votes
9 answers

Prepend text to beginning of string

What is the fastest method, to add a new value at the beginning of a string?
mate64
  • 9,876
  • 17
  • 64
  • 96
45
votes
2 answers

How does jsPerf determine which of the code snippets is fastest?

Today I visited jsPerf and now I am wondering… What is "ops/sec"? How many iterations does it do? On what basis does it calculate which is faster? What is the formula behind these calculations? Example: http://jsperf.com/concatenation-vs-join Can…
Mohit Kumar
  • 1,885
  • 5
  • 21
  • 24
20
votes
2 answers

Large substrings ~9000x faster in Firefox than Chrome: why?

The Benchmark: http://jsperf.com/substringing So, I'm starting up my very first HTML5 browser-based client-side project. It's going to have to parse very, very large text files into, essentially, an array or arrays of objects. I know how I'm going…
MischaNix
  • 730
  • 3
  • 8
17
votes
2 answers

Javascript performance of Array.map

Just wrote up some test cases in jsperf to test the difference between named and anonymous functions while using Array.map and other alternatives. http://jsperf.com/map-reduce-named-functions (excuse the url name, there is no testing of Array.reduce…
Populus
  • 7,470
  • 3
  • 38
  • 54
16
votes
3 answers

Which JS benchmark site is correct?

I created a benchmark on both jsperf.com and jsben.ch, however, they're giving substantially different results. JSPerf: https://jsperf.com/join-vs-template-venryx JSBench: http://jsben.ch/9DaxR Note that the code blocks are exactly the same. On…
Venryx
  • 15,624
  • 10
  • 70
  • 96
16
votes
1 answer

Why is a double lookup faster than a single lookup in javascript?

I am seeing some odd behavior in a jsperf test. Here is the setup: var pro={}; pro._x=3; var q=Object.create(pro); q.x=3; q.z={}; q.z.x=3; Then I simply lookup each of the properties q.x, q._x, and q.z.x. The single lookup q.x is faster than the…
gloo
  • 2,490
  • 3
  • 22
  • 38
15
votes
1 answer

Measuring JS Performance using HTML5's performance and performance.timing object

I am measuring my website's performance on the basis of performance object provided by HTML5 and I want to know that what is going wrong with my application, I also want to log these performance object of other end users in my local database so that…
Parag Bhayani
  • 3,280
  • 2
  • 28
  • 52
14
votes
1 answer

Why is .html() so much faster than .text() when used for the same purpose?

I was playing around with jQuery's .text() and .html() methods and running some simple jsPerf tests, when I was startled to discover that .html() is nearly a magnitude faster at retrieving text: $div.text() – 88,496 ops/sec $div.html() – 592,028…
Casey Falk
  • 2,617
  • 1
  • 18
  • 29
11
votes
3 answers

for loop vs forEach performance in javascript and credibility of jsperf results

I don't trust results from jsperf measuring performance of for loop vs forEach. At least for chrome and firefox on my machine results are completely different than the ones being advertised in jsperf. http://jsperf.com/foreach-vs-loop…
Diamond Hands
  • 803
  • 1
  • 10
  • 16
9
votes
3 answers

Minimizing jQuery instance vs creating more instances

I started a series of posts on javascript / jQuery optimization and stumbled upon this interesting result. Why is it that minimizing jQuery objects (by searching from a cached jQuery collection) can be slower then creating more instances of jQuery…
adardesign
  • 33,973
  • 15
  • 62
  • 84
9
votes
1 answer

Explain this JsPerf.com result

I ran a test on this website http://jsperf.com/ I want some one to explain What does green and pink signifies What is ops per second what is 95,814,583 what is +- 1.95% is whats does 'fastest' and 'slower' means
Praveen Prasad
  • 31,561
  • 18
  • 73
  • 106
8
votes
1 answer

Why does calling a function without its owner is slower?

If I do the following: var abs = Math.abs; Shoudn't abs(-10) be faster than Math.abs(-10)? Because abs is called directly. This is what called my attention: Math.abs vs custom abs function Update: The same test performed in the Internet Explorer…
wm1sr
  • 1,905
  • 1
  • 16
  • 20
8
votes
1 answer

Is it possible to delete broken revisions from jsperf?

I'm doing my first steps with jsperf (here) to improve the performance of some of my scripts. I'm wondering if it is possible to delete/remove test revisions, which I have accidentially published - they are broken and unusable, so: Question: Say I…
frequent
  • 27,643
  • 59
  • 181
  • 333
8
votes
1 answer

Impacts and benefits of creating empty object using Object.create(null)

First of all, I made a quick jsperf test case to show the obvious : Object.create(null) is way slower than creating a object with the {} syntax. http://jsperf.com/js-object-creation-null-proto But given this fact, can the former case be a good…
zoom
  • 1,686
  • 2
  • 16
  • 27
7
votes
6 answers

Fast and safe way to remove the sign of a singed number in JavaScript

I want to remove the sign of a Number in JavaScript. Here are the test cases that I already examined at jsperf if(n < 0) n *= -1; if(n < 0) n = -n; n = Math.abs(n) (n < 0) && (n *= -1) (n < 0) && (n = -n) n = Math.sqrt(n*n) According to these…
Juve
  • 10,584
  • 14
  • 63
  • 90
1
2 3 4 5