#507JP3
Лан, забенчмаркал (не ебу, что там модно в ноде для measure, поэтому наколенный timeit):
```
'use strict';
const NUMBER = 100000;
const REPEAT = 50;
function repeater(func, number) {
let total = 0;
for (let i = 0; i < number; i++) {
let hrstart = process.hrtime();
func();
let [seconds, nanoseconds] = process.hrtime(hrstart);
total += seconds + nanoseconds / 1e9;
}
return total;
}
function measure(func, number, repeat) {
let results = [];
for (let i = 0; i < repeat; i++) {
results.push(repeater(func, number));
}
let sum = results.reduce((prev, cur) => prev + cur, 0);
let mean = sum / results.length;
results.sort((a, b) => a - b);
let lowMiddle = Math.floor((results.length - 1) / 2);
let highMiddle = Math.ceil((results.length - 1) / 2);
let median = (results[lowMiddle] + results[highMiddle]) / 2;
return {
min: Math.min(...results),
max: Math.max(...results),
mean,
median,
}
}
let functions = [
function nat() {
let foo = 'FOO';
let bar = 'BAR';
[foo, bar] = [bar, foo];
},
function trans() {
let foo = 'FOO';
let bar = 'BAR';
let _ref = [bar, foo];
foo = _ref[0];
bar = _ref[1];
},
function man() {
let foo = 'FOO';
let bar = 'BAR';
let tmp = foo;
foo = bar;
bar = tmp;
},
]
for (let func of functions) {
console.log(func.name);
console.dir(measure(func, NUMBER, REPEAT));
console.log();
}
```
Будующее наступило, кек:
```
nat
{ min: 0.021939473999997218,
max: 0.03362961399999802,
mean: 0.023124280179997854,
median: 0.022092939999997584 }
trans
{ min: 0.012233300999998429,
max: 0.013627073000000092,
mean: 0.012583868739997521,
median: 0.012628050999996903 }
man
{ min: 0.013218492999997385,
max: 0.013590439999997697,
mean: 0.013309132479997161,
median: 0.01329254449999722 }
```
```
$ nodejs -v
v6.2.2
```