Overhead of iteration

Benchmark created by Steve Kane on


Description

Here we compare iterating through a list and performing multiple operations in different ways. The goal is to determine how costly (or not) it is to iterate multiple times vs performing concurrent operations in a single iteration cycle.

We are interested in this for game engine system performance comparison.

Setup

var li = new Array(10000)
    var each
    
    for (var i = 0; i < li.length; ++i) {
      li[i] = {id: i, name: "somename", age: 1}
    }
    
    function capitalizeName (obj) { 
      obj.name = obj.name.toUpperCase() 
    } 
    function increaseAge (obj) {
      obj.age++
    }

Test runner

Ready to run.

Testing in
TestOps/sec
for batched inline
for (var j = 0; j < li.length; ++j) {
  each = li[j]
  each.age++
  each.name = each.name.toUpperCase()
}
ready
for batched functions
for (var j = 0; j < li.length; ++j) {
  each = li[j]
  capitalizeName(each)
  increaseAge(each)
}
ready
for unbatched inline
for (var j = 0; j < li.length; ++j) {
  each = li[j]
  each.name = each.name.toUpperCase()
}
for (var k = 0; k < li.length; ++k) {
  li[k].age++
}
ready
for unbatched functions
for (var j = 0; j < li.length; ++j) {
  capitalizeName(li[j])
}
for (var k = 0; k < li.length; ++k) {
  increaseAge(li[k])
}
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.

  • Revision 1: published by Steve Kane on