performance-time
Task-based performance measurement utility. performance-time measures the execution time of the code you want to check.
Patch Note
- 1.1.0
Added Warmup task that runs before running first task.
As a result, the initial task no longer runs quickly. (Fixed bug)
swap1(), swap2() tasks result:
[ { task: 'swap1', repeat: 200000000, time: 620 },
{ task: 'swap2', repeat: 200000000, time: 611 } ]
API Reference
addTask(task1 [, task2, ..., taskN])
Add name of the tasks to measure performance. Tasks must be executable functions or methods.
clearTask()
Delete all tasks added through addTask.
run([obj.repeat])
Run the all added tasks and return performance time result. If add the repeat option, it will apply only to this run. Otherwise, the default(repeat = 100000) is applied.
result()
Returns Array about performance time result of the last run.
Installation
npm install performance-time
How to use
// ES5 version sample code.var Performance= ;var perf = repeat:100000000; // Add the task-functionsperf; // Run the all added tasks and print report about the run.console; //Way1: [ { task: 'swap1', repeat: 100000000, time: 60 }, // { task: 'swap2', repeat: 100000000, time: 470 } ] // Orperf; // 'repeat' only apply to this run.console; //Way2: [ { task: 'swap1', repeat: 300, time: 0 }, // { task: 'swap2', repeat: 300, time: 0 } ] // Clear all tasks added on perf.perf; /* --- Tasks */// Traditional swap which uses three variables { var a=1 b=2; var temp = a; a=b; b=temp; ifa !== 2 || b !== 1 console;} // Swap which only uses two variables { var a = 1 b = 2; a = a ^ b; b = a ^ b; a = a ^ b; ifa !== 2 || b !== 1 console;}