From ff72101b03b8d847d7ef4cd823b2ef2432130f32 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jimmy=20Nystro=CC=88m?= Date: Tue, 19 Oct 2021 15:13:14 +0200 Subject: [PATCH] Removed direct usage of performance.now Switched to using the utility function that works in both nodejs and browser environments --- src/image/image.ts | 8 ++++---- src/util/interpolate.ts | 3 ++- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/image/image.ts b/src/image/image.ts index 9ce2325d..412c4fd7 100644 --- a/src/image/image.ts +++ b/src/image/image.ts @@ -7,7 +7,7 @@ import * as fxImage from './imagefx'; import type { Tensor } from '../tfjs/types'; import type { Config } from '../config'; import { env } from '../util/env'; -import { log } from '../util/util'; +import { log, now } from '../util/util'; export type Input = Tensor | ImageData | ImageBitmap | HTMLImageElement | HTMLMediaElement | HTMLVideoElement | HTMLCanvasElement | OffscreenCanvas | typeof Image | typeof env.Canvas; @@ -229,11 +229,11 @@ const checksum = async (input: Tensor): Promise => { // use tf sum or js return sum0; }; if (benchmarked === 0) { - const t0 = performance.now(); + const t0 = now(); await jsSum(); - const t1 = performance.now(); + const t1 = now(); await tfSum(); - const t2 = performance.now(); + const t2 = now(); benchmarked = t1 - t0 < t2 - t1 ? 1 : 2; } const res = benchmarked === 1 ? await jsSum() : await tfSum(); diff --git a/src/util/interpolate.ts b/src/util/interpolate.ts index f89610da..f4b7e2cd 100644 --- a/src/util/interpolate.ts +++ b/src/util/interpolate.ts @@ -8,11 +8,12 @@ import type { Config } from '../config'; import * as moveNetCoords from '../body/movenetcoords'; import * as blazePoseCoords from '../body/blazeposecoords'; import * as efficientPoseCoords from '../body/efficientposecoords'; +import { now } from './util'; const bufferedResult: Result = { face: [], body: [], hand: [], gesture: [], object: [], persons: [], performance: {}, timestamp: 0 }; export function calc(newResult: Result, config: Config): Result { - const t0 = performance.now(); + const t0 = now(); if (!newResult) return { face: [], body: [], hand: [], gesture: [], object: [], persons: [], performance: {}, timestamp: 0 }; // each record is only updated using deep clone when number of detected record changes, otherwise it will converge by itself // otherwise bufferedResult is a shallow clone of result plus updated local calculated values