mirror of
https://github.com/weaveworks/scope.git
synced 2026-08-18 20:07:06 +00:00
Replaced timely dependency
This commit is contained in:
@@ -0,0 +1,18 @@
|
||||
import expect from 'expect';
|
||||
import timer from '../timer-utils';
|
||||
|
||||
describe('timer', () => {
|
||||
it('records how long a function takes to execute', () => {
|
||||
const add100k = (number) => {
|
||||
for (let i = 0; i < 100000; i += 1) {
|
||||
number += 1;
|
||||
}
|
||||
return number;
|
||||
};
|
||||
|
||||
const timedFn = timer(add100k);
|
||||
const result = timedFn(70);
|
||||
expect(result).toEqual(100070);
|
||||
expect(timedFn.time).toBeA('number');
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,11 @@
|
||||
// Replacement for timely dependency
|
||||
|
||||
export default function timer(fn) {
|
||||
const timedFn = (...args) => {
|
||||
const start = new Date();
|
||||
const result = fn.apply(fn, args);
|
||||
timedFn.time = new Date() - start;
|
||||
return result;
|
||||
};
|
||||
return timedFn;
|
||||
}
|
||||
Reference in New Issue
Block a user