ブロック構文の性能比較

処理にかかった時間を記述しています。数字が小さい方が高性能

ブロック自体の生成速度

ブロックなし
(function(){})()
new function(){}
with({}){}
with(createScope()){}

ブロック内の変数参照速度

名前0階層1階層2階層3階層
(function(){})()
new function(){}
with({}){}
with(createScope()){}

組み合わせ

withは遅い。しかしfunctionを組み合わせると速度が復活する

with > function
(function側スコープを参照)
with > function
(with側スコープを参照)