「returner」を含む日記 RSS

はてなキーワード: returnerとは

2009-08-07

JavaScriptラムダ式

function returner() {
    return 100;
}

function profiler(aFunction) {
    var begin = new Date();
    for (var i = 0; i < 500000; ++i) {
        aFunction();
    }
    var end = new Date();

    return end - begin;
}

function profileLambdaExpression() {
    // lamda expression
    print("lamda expression : " +
          profiler(function () returner())
         );

    // equal to above expression
    print("normal form : " +
          profiler(function () {
                       return returner();
                   })
         );

    // not return the value
    print("return no value : " +
          profiler(function () {
                       returner();
                   })
         );    
}

profileLambdaExpression();

&gt;&gt; lamda expression : 1521

&gt;&gt; normal form : 1436

&gt;&gt; return no value : 1431

SpiderMonkey 1.8.0 pre

 
ログイン ユーザー登録
ようこそ ゲスト さん