Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
<h1>Demo code for "Extreme JavaScript Performance" @ JSConf.eu</h1>
<script>
var benchmark = function(m,i){
var d1 = new Date, d2, r;
while(i--) r = m();
d2 = new Date;
console.log(d2.getTime()-d1.getTime());
// if(r) console.log(r);
}
//var str = "12.5";
//
//benchmark(function(){
// ~~(1 * str);
//}, 1000000);
//
//benchmark(function(){
// parseInt(str);
//}, 1000000);
//
//
//benchmark(function(){
// var test = '';
// for (var i = 0;i<10000;i++)
// test = test + str;
//}, 100);
//
//benchmark(function(){
// var test = '', i = 10000;
// while(i--) test = test + str;
//}, 100);
//benchmark(function(){
// var w = window, i = 10000;
// while(i--) w.test = 'test';
//}, 100);
//
//benchmark(function(){
// var i = 10000;
// while(i--) window.test = 'test';
//}, 100);
//var b = true, n = 99;
//
//benchmark(function(){
// return n*n || b;
//}, 1000000);
//
//benchmark(function(){
// return b || n*n;
//}, 1000000);
//benchmark(function(){
// var obj = { prop: 'test', str: '' };
// with(obj){
// var i = 10000;
// while(i--) str += prop;
// return str;
// }
//}, 10);
//
//benchmark(function(){
// var obj = { prop: 'test', str: '' }, i = 10000;
// while(i--) obj.str += obj.prop;
// return obj.str;
//}, 10);
var a = 0;
benchmark(function(){
try{
a += 1;
} catch(e) {}
}, 1000000);
benchmark(function(){
a += 1;
}, 1000000);
(function(){ return 2 * 3; }).toString();
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.