Sparse arrays vs full arrays

JavaScript performance comparison

Test case created by Mattias Ernelli

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  var n, N, i, I, sparse = [],
      full = [],
      full2 = [];
  
  N = 16384;
  I = 8;
  
  for (i = 0; i < I; i++) {
    do {
      n = (N * Math.random()) | 0;
      if (n > (N - 1)) {
        n = N - 1;
      }
    } while (sparse[n]);
    sparse[n] = -100 + 200 * Math.random();
  }
  full.length = N;
  full2.length = N;
  for (i = 0; i < N; i++) {
    if (typeof sparse[i] === "number") {
      full[i] = sparse[i];
      full2[i] = sparse[i];
    } else {
      full[i] = 0;
      full2[i] = -100 + 200 * Math.random();
    }
  }

};
</script>

Test runner

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

Java applet disabled.

Testing in CCBot 2.0.0 / Other 0.0.0
Test Ops/sec
Sparse array sum
var sum = 0;
sparse.forEach(function(v, i) {
  sum += v;
});
pending…
Full array sum
var len = full.length;
sum = 0;
for (i = 0; i < len; i++) {
  sum += full[i];
}
pending…
Running sparse on full array
var sum = 0;
full.forEach(function(v, i) {
  sum += v;
});
pending…
Sum all elements on a full array without zeros
var len = full2.length;
sum = 0;
for (i = 0; i < len; i++) {
  sum += full2[i];
}
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.

2 Comments

Mattias Ernelli (revision owner) commented :

OK, thats it, Sparse arrays in JS is way slower than just processing all elements of the array. Even if less than 1% of the sparse array is populated.

I will remove all code supporting sparse arrays in my numjs library which I'm working on from time to time...

polo2016 commented :

let belstaff outlet him jordan retro know timberland boots the patriots jerseys results swarovski jewelry of nike free 5.0 a mizuno running crystal panthers jerseys shop hollister online owner, giuseppe zanotti sneakers he oklahoma city thunder jersey followed under armour "a nike air max person new york knicks closer replica watches dream, pandora charms destiny ralph lauren became ray bans outlet more air max and buccaneers jerseys more softball bats into babyliss pro Taishan ralph lauren polos collapse burberry sale in michael kors outlet online the michael kors v?skor former toms shoes outlet and texans jerseys without swarovski blinking rams jerseys an broncos jerseys eye, pandora charms thousands nike roshe of michael kors outlet online people, mizuno wave such cheap oakley as phoenix suns jersey unhindered. vans outlet Win links of london outlet without louboutin shoes pride, cowboys jerseys lose nike roshe with the north face grace. coach factory A titans jerseys man, new balance if replica watches life coach factory outlet and soccer shoes death, steelers jerseys indifferent, bears jerseys Dankan versace outlet online gains vikings jerseys and michael kors losses mcm backpack tend ray bans to ray-ban sunglasses be oakley frogskins a burberry outlet survivor, denver nuggets jerseys get ralph lauren factory store a oakley sunglasses windfall. cheap ray ban There michael kors canada is a fred perry polos story memphis grizzlies jersey that juicy couture outlet a huarache selling swarovski australia bean cheap michael kors curd, parajumpers and raiders jerseys suddenly nike outlet unexpectedly coach outlet received ecco outlet challenge vans schuhe a red bottoms warrior, jerseys from china lives jimmy choo outlet are indoor soccer shoes at air max schoenen stake. coach factory shop He christian louboutin shoes asked coach outlet canada a philadelphia 76ers jerseys Zen nike air max master ralph lauren outlet online to hermes save burberry outlet online his hermes belt life, the north face Jackson michael kors taught guess outlet him chrome hearts to north face jackets calm calvin klein underwear down, minnesota timberwolves jersey not coach outlet online to burberry sale fight toms.com as a skechers duel, new orleans pelicans jersey as ray ban sunglasses outlet tofu reebok shoes outlet can indiana pacers jersey be. nike air max Time tommy hilfiger to nike free 5.0 duel, cheap nba jerseys saw nike store Maidou coach outlet online Fu calmly, rolex gently jimmy choo shoes hats ray ban wayfarer off, nike air max 90 on timberland outlet the Sac Hermes bench. michael kors Do ed hardy clothing not ray ban outlet hurry gucci shoes outlet hurry, 49ers jerseys slowly untied ralph lauren outlet robe, fivefingers lightly mcm backpack dust tommy hilfiger outlet shells nike air jordan robes, michael kors outlet folded ferragamo shoes carefully seahawks jerseys and slowly jordan release dates 2015 on nike huarache the pandora schmuck bench, converse outlet then ferragamo shoes went michael kors uk over jordans to coach outlet online faint, ralph lauren outlet slowly brooklyn nets jerseys pulled baseball bats out hogan outlet a reloj long mcm backpack outlet knife, pandora canada even ralph lauren outlet in giants jerseys the north face outlet eye nike.dk did montblanc not barbour jackets see armani outlet the adidas superstar warrior the north face a. burberry Suddenly, uggs outlet the cheap nfl jerseys warrior michael kors bags splash, new balance canada knees, tory burch outlet and bcbg max azria dropped hugo boss shop the nike free run hands toronto raptors jersey of oakley vault the handbags outlet knife. birkenstock deutschland Samurai juicy couture handbags by nike schoenen his hermes bags calm adidas.se and purses and handbags relaxed north face backpacks overawed, burberry outlet store utterly san antonio spurs jerseys demoralized. nike tn So air jordan retro calm, cheap true religion it tory burch must birkenstock outlet be adidas superstar world barbour outlet outside nike shop expert! true religion jeans women In cheap basketball shoes fact, the north face outlet we jack wolfskin outlet are tommy hilfiger often puma online lost rayban their polo outlet store own, nfl jerseys so moncler mens jackets that baseball jerseys we coach factory outlet fail, fitflop outlet the converse shoes outcome coach outlet online is swarovski crystal sinking chargers jerseys heart.Calm coach outlet online and valentino outlet quiet, supra footwear it soccer shoes outlet is glasses frames a michael kors canada realm golden state warriors jersey of salomon schuhe life, los angeles clippers jersey is nike schuhe a polo ralph life tommy hilfiger outlet stores attitude. stone island polos Northern watches canada Song mcm handbags Wenhao michael kors outlet Dongpo, adidas canada and michael kors Jackson oakley sungalsses outlet Foyin cleveland cavaliers are michael kors good nike air max friends. longchamp outlet One packers jerseys day, browns jerseys he true religion jeans outlet enlightened, adidas online realize cheap oakley sunglasses "eight wind knockoff handbags does michael kors outlet not coach purses outlet online move," bills jerseys the dsquared2 sale Zen, birkenstock shoes very michael jordan proud, omega watches immediately pandora brush lacoste shoes to write hogan outlet these ray ban occhiali five nike shoes words. Busy moncler outlet online nunnery thomas sabo jewellery sent nike air force the ralph lauren polo word air jordan to free running the coach outlet other new balance outlet side timberland femme of gucci shoes the asics gel river polo ralph lauren there bottega veneta Foyin marc by marc jacobs correction. north face After thomas sabo Yin mcm bags see baseball jerseys below dallas mavericks jerseys Phi burberry online shop a baseball jerseys word: ray ban wayfarer fart. oakley sunglasses outlet Sushi adidas superstar annoyed falcons jerseys by givenchy outlet boat michael kors across detroit pistons the chi flat iron river air yeezy shoes to prada shoes the thomas sabo uk theory. cheap nba jerseys Yin lunette ray ban indifferent polo ralph lauren outlet online smile, guciheaven shoes said: jerseys from china "Eight wind air max does polo ralph not boots on sale move, rolex watches for sale across belstaff outlet online the barbour outlet river skechers to louboutin a converse chucks fart." nike mercurial vapor Dongpo levis jeans several www.tommyhilfiger.nl ups hollister clothing and prada sunglasses downs oakley sunglasses in coach factory politics, nba jerseys after stephen curry shoes the saints jerseys low ralph lauren outlet life, giuseppe shoes awareness ray ban zonnebril of prada outlet this oakley sunglasses life mont blanc is prada outlet meant azcardinals jerseys to oakley be veneta light, polo ralph lauren outlet become mbt shoes outlet chic colts jerseys -. pandora bracelet "Mo louboutin shoes listen burberry handbags Chuan hoodies Lin gafas oakley beat katespade Ye, swarovski jewelry why charlotte hornets jerseys Yin burberry outlet online Xiao belstaff and celine bags Xing vans shoes Xu oakley vault Zhu nfl jerseys Zhang houston rockets jerseys Mans longchamp shoes hollister clothing store light redskins jerseys horse guess factory outlet , michael kors outlet online who's lunette ray ban afraid? nike shoes Yisuoyanyu chiefs jerseys Renping ralph lauren polos Sheng. lacoste polos "Every tods outlet ordinary nike air max thea people, new balance more jaguars jerseys than fendi handbags half nike outlet of barbour jackets outlet the true religion road hollister kids of new balance life fred perry outlet is salvatore ferragamo wind air max and atlanta hawks jerseys rain, ray ban most roshe run of nike air max the red bottom shoes ups jerseys from china and chicago bulls jersey downs. oakley canada Only katespade calm ferragamo in burberry outlet online the hilfiger online shop face, ralph lauren outlet online accept cheap oakley it, philipp plein outlet I burberry outlet do ferragamo shoes uk not oakley outlet feel skechers outlet bitter. rolex watches The longchamp handbags bitter hollister kids life, oakley sunglasses cheap not eagles jerseys afraid jets jerseys to ralph lauren outlet have michael kors outlet online a washington wizards jersey bitter sacramento kings jersey heart, coach outlet in michael kors bags order ray ban sonnenbrillen to northface taste hogan the versace outlet online bitter fossil uhren to toms outlet online sweet asics outlet taste. cc beanies Since kate spade outlet online ancient dolphins jerseys times, adidas Huashan, asics a nike roshe road, puma outlet trail converse sneakers in iphone case the roshe run cliffs abercrombie that omega watches can michael kors taschen be chic Xu true religion jeans line coach store for barbour factory you, nike free 5.0 and toms shoes how tracksuits store many? michael kors outlet online sale "Paper purses and handbags come adidas online I ralph lauren felt supra footwear light, timberland shoes must burberry outlet know air max this woolrich outlet practice ray bans is longchamp taschen essential." nike.se Read orlando magic jersey a longchamp outlet lot michael kors purses better ravens jerseys than coach black friday reading swarovski online ten toms shoes outlet thousand ugg boots books, plein shoes Zen air huarache Hui oakley Neng, kate spade outlet online illiterate, air jordan shoes able christian louboutin shoes to chi hair deep iphone 5s cases understanding fidget spinner outlet of utah jazz jersey nature, long champ calm pandora on tommy hilfiger online the ralph lauren road, under armour shoes we cheap michael kors can jack wolfskin jackets say, reebok road lions jerseys in portland trail blazers jersey life, burberry sale in air max 2015 nature.Reading bengals jerseys philosophical milwaukee bucks jersey Essay, hollisterco the nike air max shoes maximum ralph lauren sentence north face is long champ read: oakley sunglasses outlet "Rain prada or true religion outlet shine, rolex watch see rayban Pretrial toms outlet blossom; zapatillas nike fate roshe run not, montre homme look Yunjuanyunshu dsquared2 air." In heat jerseys fact, dansko outlet Tao jerseys from china is glasses online very marc by marc jacobs simple, christian louboutin shoes life boston celtics jersey is lakers jerseys very bcbg max

ray ban sunglasses