Skip to content

Commit

Permalink
Move measure performance function into utils
Browse files Browse the repository at this point in the history
  • Loading branch information
mdaines committed Aug 30, 2024
1 parent 9034304 commit 271c55f
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 36 deletions.
19 changes: 1 addition & 18 deletions packages/viz/test/manual/performance-object.mjs
Original file line number Diff line number Diff line change
@@ -1,22 +1,5 @@
import { instance } from "../../src/standalone.mjs";
import { randomGraph, dotStringify } from "./utils.mjs";

function measure(operation, timeLimit) {
let callCount = 0;

const startTime = performance.now();

while (performance.now() - startTime < timeLimit) {
operation();
callCount++;
}

const stopTime = performance.now();
const duration = (stopTime - startTime) / 1000;
const speed = callCount / duration;

return `${callCount} in ${duration.toFixed(2)} s, ${speed.toFixed(2)} calls/s`
}
import { measure, randomGraph, dotStringify } from "./utils.mjs";

const tests = [
{ nodeCount: 100, randomEdgeCount: 10 },
Expand Down
26 changes: 8 additions & 18 deletions packages/viz/test/manual/performance-timing.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { instance } from "../../src/standalone.mjs";
import { randomGraph, dotStringify } from "./utils.mjs";
import { measure, randomGraph, dotStringify } from "./utils.mjs";

const tests = [
{ nodeCount: 100, randomEdgeCount: 0 },
Expand All @@ -13,24 +13,14 @@ const tests = [
{ nodeCount: 100, randomEdgeCount: 300 }
];

tests.forEach(test => {
test.input = dotStringify(randomGraph(test.nodeCount, test.randomEdgeCount));
});

const timeLimit = 5000;

for (const { nodeCount, randomEdgeCount } of tests) {
for (const { input, nodeCount, randomEdgeCount } of tests) {
const viz = await instance();
const src = dotStringify(randomGraph(nodeCount, randomEdgeCount));

let callCount = 0;

const startTime = performance.now();

while (performance.now() - startTime < timeLimit) {
viz.render(src);
callCount++;
}

const stopTime = performance.now();
const duration = (stopTime - startTime) / 1000;
const speed = callCount / duration;

console.log(`${nodeCount} nodes, ${randomEdgeCount} edges: ${callCount} in ${duration.toFixed(2)} s, ${speed.toFixed(2)} calls/s`);
const result = measure(() => viz.render(input), timeLimit);
console.log(`${nodeCount} nodes, ${randomEdgeCount} edges: ${result}`);
}
17 changes: 17 additions & 0 deletions packages/viz/test/manual/utils.mjs
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
export function measure(operation, timeLimit) {
let callCount = 0;

const startTime = performance.now();

while (performance.now() - startTime < timeLimit) {
operation();
callCount++;
}

const stopTime = performance.now();
const duration = (stopTime - startTime) / 1000;
const speed = callCount / duration;

return `${callCount} in ${duration.toFixed(2)} s, ${speed.toFixed(2)} calls/s`
}

const skipQuotePattern = /^([A-Za-z_][A-Za-z_0-9]*|-?(\.[0-9]+|[0-9]+(\.[0-9]+)?))$/;

function quote(value) {
Expand Down

0 comments on commit 271c55f

Please sign in to comment.