Skip to content

Instantly share code, notes, and snippets.

@bomberstudios
Created October 22, 2010 10:19
Show Gist options
  • Save bomberstudios/640293 to your computer and use it in GitHub Desktop.
Save bomberstudios/640293 to your computer and use it in GitHub Desktop.
A simple benchmark comparing Fireworks CS3 and Bohemian Coding Sketch. Same code can be run on both (save as .jsf for Fireworks and .jstalk for Sketch)
// redefine log() if we are inside Fireworks
if (!this['log']) {
log = alert;
}
log('Starting benchmark - ' + new Date());
// Benchmark function
function benchmark(func,msg){
start = new Date();
func.call();
end = new Date();
log('Benchmark: ' + msg + '\n' + (end - start) + ' ms.');
};
// Utility methods
Array.prototype.each = function(callback){
for (var i = this - 1; i >= 0; i--){
callback.call(this,this[i]);
};
};
Number.prototype.times = function(callback){
for (var s = this - 1; s >= 0; s--){
callback.call(this,s);
};
};
// Setup
var arr = new Array(10000000);
var f = function(){
(10000000).times(function(){
//
});
};
var p = function(i){
// do nothing
};
var d = function(){
(10000000).times(function(){
b = 'logging: ' + arguments[0];
});
};
var d2 = function(a){
(10000000).times(function(){
b = 'logging: ' + a;
});
};
benchmark(function(){
for (var i=0; i < arr.length; i++) {
// CS3: 2874
// Sketch: 67
};
},'simple loop');
benchmark(function(){
var i = arr.length - 1;
for (i; i >= 0; i--){
// CS3: 2055
// Sketch: 34
};
},'inverse loop');
benchmark(function(){
// Sketch: 264
// CS3: 12546
f();
},'function that does nothing');
benchmark(function(){
// Sketch: 2712
// CS3: 30775
d(1);
},'function without parameter, using arguments');
benchmark(function(){
// Sketch: 826
// CS3: 30959
d2(1);
},'function with parameter, using fixed parameter');
benchmark(function(){
// Sketch: 1485
// CS3: 24786
d2();
},'function with parameter, using empty parameter');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment