From 9dfcd213c32470b7e465a8bf60b4dd631589e5cd Mon Sep 17 00:00:00 2001 From: jpellizzari Date: Tue, 21 Mar 2017 12:26:52 -0700 Subject: [PATCH] Replaced timely dependency --- .../app/scripts/selectors/nodes-chart-graph.js | 4 ++-- .../utils/__tests__/timer-utils-test.js | 18 ++++++++++++++++++ client/app/scripts/utils/timer-utils.js | 11 +++++++++++ client/package.json | 1 - 4 files changed, 31 insertions(+), 3 deletions(-) create mode 100644 client/app/scripts/utils/__tests__/timer-utils-test.js create mode 100644 client/app/scripts/utils/timer-utils.js diff --git a/client/app/scripts/selectors/nodes-chart-graph.js b/client/app/scripts/selectors/nodes-chart-graph.js index a8728d4b5..12aaf635b 100644 --- a/client/app/scripts/selectors/nodes-chart-graph.js +++ b/client/app/scripts/selectors/nodes-chart-graph.js @@ -1,13 +1,13 @@ import debug from 'debug'; import { createSelector, createStructuredSelector } from 'reselect'; import { Map as makeMap } from 'immutable'; -import timely from 'timely'; import { initEdgesFromNodes } from '../utils/layouter-utils'; import { viewportWidthSelector, viewportHeightSelector } from './canvas-viewport'; import { activeTopologyOptionsSelector } from './topology'; import { shownNodesSelector } from './node-filters'; import { doLayout } from '../charts/nodes-layout'; +import timer from '../utils/timer-utils'; const log = debug('scope:nodes-chart'); @@ -49,7 +49,7 @@ const graphLayoutSelector = createSelector( } const edges = initEdgesFromNodes(nodes); - const timedLayouter = timely(doLayout); + const timedLayouter = timer(doLayout); const graph = timedLayouter(nodes, edges, options); // NOTE: We probably shouldn't log anything in a diff --git a/client/app/scripts/utils/__tests__/timer-utils-test.js b/client/app/scripts/utils/__tests__/timer-utils-test.js new file mode 100644 index 000000000..de7cc6129 --- /dev/null +++ b/client/app/scripts/utils/__tests__/timer-utils-test.js @@ -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'); + }); +}); diff --git a/client/app/scripts/utils/timer-utils.js b/client/app/scripts/utils/timer-utils.js new file mode 100644 index 000000000..c03032891 --- /dev/null +++ b/client/app/scripts/utils/timer-utils.js @@ -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; +} diff --git a/client/package.json b/client/package.json index 7ec3db86b..4603ade29 100644 --- a/client/package.json +++ b/client/package.json @@ -40,7 +40,6 @@ "reqwest": "2.0.5", "reselect": "2.5.4", "reselect-map": "1.0.0", - "timely": "0.1.0", "whatwg-fetch": "2.0.1", "react-addons-perf": "15.4.2", "xterm": "2.2.3"