Skip to content

Commit

Permalink
pretty print timer output (#68)
Browse files Browse the repository at this point in the history
  • Loading branch information
kubikowski authored Nov 9, 2022
1 parent 31b8472 commit fa81956
Show file tree
Hide file tree
Showing 15 changed files with 184 additions and 25 deletions.
4 changes: 3 additions & 1 deletion test/scale/comparisons/disjoint.function.scale.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { afterAll, describe, expect, it, jest } from '@jest/globals';
import { afterAll, beforeAll, describe, expect, it, jest } from '@jest/globals';
import { disjoint } from '../../../src';
import { ScaleTestSets } from '../../util/scale/scale-test-sets.model';
import { padding, times } from '../../util/scale/scale-test.constants';
Expand Down Expand Up @@ -46,6 +46,7 @@ describe('disjoint @ scale', () => {

describe('disjoint ⋅ many sets', () => {
const { manyDisjoint, manyEquivalent, someDisjoint, someEquivalent } = ScaleTestSets;
beforeAll(() => Timer.nextLine('disjoint'));

it('disjoint(100 Equivalent):'.padEnd(padding), () => {
const result = Timer.time('disjoint', () => disjoint(...someEquivalent));
Expand All @@ -70,6 +71,7 @@ describe('disjoint @ scale', () => {

describe('disjoint ⋅ many times', () => {
const { coupleDisjoint, coupleEquivalent, fewDisjoint, fewEquivalent } = ScaleTestSets;
beforeAll(() => Timer.nextLine('disjoint'));

it('100k ⋅ disjoint(2 Equivalent):'.padEnd(padding), () => {
const disjointMock = jest.fn(disjoint);
Expand Down
4 changes: 3 additions & 1 deletion test/scale/comparisons/equivalence.function.scale.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { afterAll, describe, expect, it, jest } from '@jest/globals';
import { afterAll, beforeAll, describe, expect, it, jest } from '@jest/globals';
import { equivalence } from '../../../src';
import { ScaleTestSets } from '../../util/scale/scale-test-sets.model';
import { padding, times } from '../../util/scale/scale-test.constants';
Expand Down Expand Up @@ -46,6 +46,7 @@ describe('equivalence @ scale', () => {

describe('equivalence ⋅ many sets', () => {
const { manyDisjoint, manyEquivalent, someDisjoint, someEquivalent } = ScaleTestSets;
beforeAll(() => Timer.nextLine('equivalence'));

it('equivalence(100 Equivalent):'.padEnd(padding), () => {
const result = Timer.time('equivalence', () => equivalence(...someEquivalent));
Expand All @@ -70,6 +71,7 @@ describe('equivalence @ scale', () => {

describe('equivalence ⋅ many times', () => {
const { coupleDisjoint, coupleEquivalent, fewDisjoint, fewEquivalent } = ScaleTestSets;
beforeAll(() => Timer.nextLine('equivalence'));

it('100k ⋅ equivalence(2 Equivalent):'.padEnd(padding), () => {
const equivalenceMock = jest.fn(equivalence);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { afterAll, describe, expect, it, jest } from '@jest/globals';
import { afterAll, beforeAll, describe, expect, it, jest } from '@jest/globals';
import { pairwiseDisjoint } from '../../../src';
import { ScaleTestSets } from '../../util/scale/scale-test-sets.model';
import { padding, times } from '../../util/scale/scale-test.constants';
Expand Down Expand Up @@ -46,6 +46,7 @@ describe('pairwise disjoint @ scale', () => {

describe('pairwise disjoint ⋅ many sets', () => {
const { manyDisjoint, manyEquivalent, someDisjoint, someEquivalent } = ScaleTestSets;
beforeAll(() => Timer.nextLine('pairwiseDisjoint'));

it('pairwiseDisjoint(100 Equivalent):'.padEnd(padding), () => {
const result = Timer.time('pairwiseDisjoint', () => pairwiseDisjoint(...someEquivalent));
Expand All @@ -70,6 +71,7 @@ describe('pairwise disjoint @ scale', () => {

describe('pairwise disjoint ⋅ many times', () => {
const { coupleDisjoint, coupleEquivalent, fewDisjoint, fewEquivalent } = ScaleTestSets;
beforeAll(() => Timer.nextLine('pairwiseDisjoint'));

it('100k ⋅ pairwiseDisjoint(2 Equivalent):'.padEnd(padding), () => {
const pairwiseDisjointMock = jest.fn(pairwiseDisjoint);
Expand Down
4 changes: 3 additions & 1 deletion test/scale/comparisons/proper-subset.function.scale.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { afterAll, describe, expect, it, jest } from '@jest/globals';
import { afterAll, beforeAll, describe, expect, it, jest } from '@jest/globals';
import { properSubset } from '../../../src';
import { ScaleTestSets } from '../../util/scale/scale-test-sets.model';
import { padding, times } from '../../util/scale/scale-test.constants';
Expand Down Expand Up @@ -46,6 +46,7 @@ describe('proper subset @ scale', () => {

describe('proper subset ⋅ many sets', () => {
const { manyDisjoint, manyEquivalent, someDisjoint, someEquivalent } = ScaleTestSets;
beforeAll(() => Timer.nextLine('properSubset'));

it('properSubset(100 Equivalent):'.padEnd(padding), () => {
const result = Timer.time('properSubset', () => properSubset(...someEquivalent));
Expand All @@ -70,6 +71,7 @@ describe('proper subset @ scale', () => {

describe('proper subset ⋅ many times', () => {
const { coupleDisjoint, coupleEquivalent, fewDisjoint, fewEquivalent } = ScaleTestSets;
beforeAll(() => Timer.nextLine('properSubset'));

it('100k ⋅ properSubset(2 Equivalent):'.padEnd(padding), () => {
const properSubsetMock = jest.fn(properSubset);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { afterAll, describe, expect, it, jest } from '@jest/globals';
import { afterAll, beforeAll, describe, expect, it, jest } from '@jest/globals';
import { properSuperset } from '../../../src';
import { ScaleTestSets } from '../../util/scale/scale-test-sets.model';
import { padding, times } from '../../util/scale/scale-test.constants';
Expand Down Expand Up @@ -46,6 +46,7 @@ describe('proper superset @ scale', () => {

describe('proper superset ⋅ many sets', () => {
const { manyDisjoint, manyEquivalent, someDisjoint, someEquivalent } = ScaleTestSets;
beforeAll(() => Timer.nextLine('properSuperset'));

it('properSuperset(100 Equivalent):'.padEnd(padding), () => {
const result = Timer.time('properSuperset', () => properSuperset(...someEquivalent));
Expand All @@ -70,6 +71,7 @@ describe('proper superset @ scale', () => {

describe('proper superset ⋅ many times', () => {
const { coupleDisjoint, coupleEquivalent, fewDisjoint, fewEquivalent } = ScaleTestSets;
beforeAll(() => Timer.nextLine('properSuperset'));

it('100k ⋅ properSuperset(2 Equivalent):'.padEnd(padding), () => {
const properSupersetMock = jest.fn(properSuperset);
Expand Down
4 changes: 3 additions & 1 deletion test/scale/comparisons/subset.function.scale.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { afterAll, describe, expect, it, jest } from '@jest/globals';
import { afterAll, beforeAll, describe, expect, it, jest } from '@jest/globals';
import { subset } from '../../../src';
import { ScaleTestSets } from '../../util/scale/scale-test-sets.model';
import { padding, times } from '../../util/scale/scale-test.constants';
Expand Down Expand Up @@ -46,6 +46,7 @@ describe('subset @ scale', () => {

describe('subset ⋅ many sets', () => {
const { manyDisjoint, manyEquivalent, someDisjoint, someEquivalent } = ScaleTestSets;
beforeAll(() => Timer.nextLine('subset'));

it('subset(100 Equivalent):'.padEnd(padding), () => {
const result = Timer.time('subset', () => subset(...someEquivalent));
Expand All @@ -70,6 +71,7 @@ describe('subset @ scale', () => {

describe('subset ⋅ many times', () => {
const { coupleDisjoint, coupleEquivalent, fewDisjoint, fewEquivalent } = ScaleTestSets;
beforeAll(() => Timer.nextLine('subset'));

it('100k ⋅ subset(2 Equivalent):'.padEnd(padding), () => {
const subsetMock = jest.fn(subset);
Expand Down
4 changes: 3 additions & 1 deletion test/scale/comparisons/superset.function.scale.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { afterAll, describe, expect, it, jest } from '@jest/globals';
import { afterAll, beforeAll, describe, expect, it, jest } from '@jest/globals';
import { superset } from '../../../src';
import { ScaleTestSets } from '../../util/scale/scale-test-sets.model';
import { padding, times } from '../../util/scale/scale-test.constants';
Expand Down Expand Up @@ -46,6 +46,7 @@ describe('superset @ scale', () => {

describe('superset ⋅ many sets', () => {
const { manyDisjoint, manyEquivalent, someDisjoint, someEquivalent } = ScaleTestSets;
beforeAll(() => Timer.nextLine('superset'));

it('superset(100 Equivalent):'.padEnd(padding), () => {
const result = Timer.time('superset', () => superset(...someEquivalent));
Expand All @@ -70,6 +71,7 @@ describe('superset @ scale', () => {

describe('superset ⋅ many times', () => {
const { coupleDisjoint, coupleEquivalent, fewDisjoint, fewEquivalent } = ScaleTestSets;
beforeAll(() => Timer.nextLine('superset'));

it('100k ⋅ superset(2 Equivalent):'.padEnd(padding), () => {
const supersetMock = jest.fn(superset);
Expand Down
4 changes: 3 additions & 1 deletion test/scale/operations/difference.function.scale.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { afterAll, describe, expect, it, jest } from '@jest/globals';
import { afterAll, beforeAll, describe, expect, it, jest } from '@jest/globals';
import { difference } from '../../../src';
import { ScaleTestSets } from '../../util/scale/scale-test-sets.model';
import { padding, times } from '../../util/scale/scale-test.constants';
Expand Down Expand Up @@ -46,6 +46,7 @@ describe('difference @ scale', () => {

describe('difference ⋅ many sets', () => {
const { manyDisjoint, manyEquivalent, someDisjoint, someEquivalent } = ScaleTestSets;
beforeAll(() => Timer.nextLine('difference'));

it('difference(100 Equivalent):'.padEnd(padding), () => {
const result = Timer.time('difference', () => difference(...someEquivalent));
Expand All @@ -70,6 +71,7 @@ describe('difference @ scale', () => {

describe('difference ⋅ many times', () => {
const { coupleDisjoint, coupleEquivalent, fewDisjoint, fewEquivalent } = ScaleTestSets;
beforeAll(() => Timer.nextLine('difference'));

it('100k ⋅ difference(2 Equivalent):'.padEnd(padding), () => {
const differenceMock = jest.fn(difference);
Expand Down
4 changes: 3 additions & 1 deletion test/scale/operations/intersection.function.scale.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { afterAll, describe, expect, it, jest } from '@jest/globals';
import { afterAll, beforeAll, describe, expect, it, jest } from '@jest/globals';
import { intersection } from '../../../src';
import { ScaleTestSets } from '../../util/scale/scale-test-sets.model';
import { padding, times } from '../../util/scale/scale-test.constants';
Expand Down Expand Up @@ -46,6 +46,7 @@ describe('intersection @ scale', () => {

describe('intersection ⋅ many sets', () => {
const { manyDisjoint, manyEquivalent, someDisjoint, someEquivalent } = ScaleTestSets;
beforeAll(() => Timer.nextLine('intersection'));

it('intersection(100 Equivalent):'.padEnd(padding), () => {
const result = Timer.time('intersection', () => intersection(...someEquivalent));
Expand All @@ -70,6 +71,7 @@ describe('intersection @ scale', () => {

describe('intersection ⋅ many times', () => {
const { coupleDisjoint, coupleEquivalent, fewDisjoint, fewEquivalent } = ScaleTestSets;
beforeAll(() => Timer.nextLine('intersection'));

it('100k ⋅ intersection(2 Equivalent):'.padEnd(padding), () => {
const intersectionMock = jest.fn(intersection);
Expand Down
4 changes: 3 additions & 1 deletion test/scale/operations/union.function.scale.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { afterAll, describe, expect, it, jest } from '@jest/globals';
import { afterAll, beforeAll, describe, expect, it, jest } from '@jest/globals';
import { union } from '../../../src';
import { ScaleTestSets } from '../../util/scale/scale-test-sets.model';
import { padding, times } from '../../util/scale/scale-test.constants';
Expand Down Expand Up @@ -46,6 +46,7 @@ describe('union @ scale', () => {

describe('union ⋅ many sets', () => {
const { manyDisjoint, manyEquivalent, someDisjoint, someEquivalent } = ScaleTestSets;
beforeAll(() => Timer.nextLine('union'));

it('union(100 Equivalent):'.padEnd(padding), () => {
const result = Timer.time('union', () => union(...someEquivalent));
Expand All @@ -70,6 +71,7 @@ describe('union @ scale', () => {

describe('union ⋅ many times', () => {
const { coupleDisjoint, coupleEquivalent, fewDisjoint, fewEquivalent } = ScaleTestSets;
beforeAll(() => Timer.nextLine('union'));

it('100k ⋅ union(2 Equivalent):'.padEnd(padding), () => {
const unionMock = jest.fn(union);
Expand Down
4 changes: 3 additions & 1 deletion test/scale/operations/xor.function.scale.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { afterAll, describe, expect, it, jest } from '@jest/globals';
import { afterAll, beforeAll, describe, expect, it, jest } from '@jest/globals';
import { xor } from '../../../src';
import { ScaleTestSets } from '../../util/scale/scale-test-sets.model';
import { padding, times } from '../../util/scale/scale-test.constants';
Expand Down Expand Up @@ -46,6 +46,7 @@ describe('xor @ scale', () => {

describe('xor ⋅ many sets', () => {
const { manyDisjoint, manyEquivalent, someDisjoint, someEquivalent } = ScaleTestSets;
beforeAll(() => Timer.nextLine('xor'));

it('xor(100 Equivalent):'.padEnd(padding), () => {
const result = Timer.time('xor', () => xor(...someEquivalent));
Expand All @@ -70,6 +71,7 @@ describe('xor @ scale', () => {

describe('xor ⋅ many times', () => {
const { coupleDisjoint, coupleEquivalent, fewDisjoint, fewEquivalent } = ScaleTestSets;
beforeAll(() => Timer.nextLine('xor'));

it('100k ⋅ xor(2 Equivalent):'.padEnd(padding), () => {
const xorMock = jest.fn(xor);
Expand Down
3 changes: 2 additions & 1 deletion test/scale/ordering/sort.function.scale.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { afterAll, describe, expect, it, jest } from '@jest/globals';
import { afterAll, beforeAll, describe, expect, it, jest } from '@jest/globals';
import { sort } from '../../../src';
import { ScaleTestSets } from '../../util/scale/scale-test-sets.model';
import { padding, times } from '../../util/scale/scale-test.constants';
Expand Down Expand Up @@ -59,6 +59,7 @@ describe('sort @ scale', () => {

describe('sort ⋅ many times', () => {
const { manyUnordered } = ScaleTestSets;
beforeAll(() => Timer.nextLine('sort'));

it('100k ⋅ sort(100):'.padEnd(padding), () => {
const sortMock = jest.fn(sort<number>);
Expand Down
58 changes: 58 additions & 0 deletions test/util/scale/ansi-format.model.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
abstract class AnsiEscapeSequences {

/* Foreground Colors */
public static readonly FG_BLACK = '\x1B[30m';
public static readonly FG_RED = '\x1B[31m';
public static readonly FG_GREEN = '\x1B[32m';
public static readonly FG_YELLOW = '\x1B[33m';
public static readonly FG_BLUE = '\x1B[34m';
public static readonly FG_MAGENTA = '\x1B[35m';
public static readonly FG_CYAN = '\x1B[36m';
public static readonly FG_WHITE = '\x1B[37m';

/* Resets */
public static readonly FG_OFF = '\x1B[39m';
}

export abstract class AnsiFormat {

public static fgBlack(text: string): string {
const { FG_BLACK, FG_OFF } = AnsiEscapeSequences;
return `${ FG_BLACK }${ text }${ FG_OFF }`;
}

public static fgRed(text: string): string {
const { FG_RED, FG_OFF } = AnsiEscapeSequences;
return `${ FG_RED }${ text }${ FG_OFF }`;
}

public static fgGreen(text: string): string {
const { FG_GREEN, FG_OFF } = AnsiEscapeSequences;
return `${ FG_GREEN }${ text }${ FG_OFF }`;
}

public static fgYellow(text: string): string {
const { FG_YELLOW, FG_OFF } = AnsiEscapeSequences;
return `${ FG_YELLOW }${ text }${ FG_OFF }`;
}

public static fgBlue(text: string): string {
const { FG_BLUE, FG_OFF } = AnsiEscapeSequences;
return `${ FG_BLUE }${ text }${ FG_OFF }`;
}

public static fgMagenta(text: string): string {
const { FG_MAGENTA, FG_OFF } = AnsiEscapeSequences;
return `${ FG_MAGENTA }${ text }${ FG_OFF }`;
}

public static fgCyan(text: string): string {
const { FG_CYAN, FG_OFF } = AnsiEscapeSequences;
return `${ FG_CYAN }${ text }${ FG_OFF }`;
}

public static fgWhite(text: string): string {
const { FG_WHITE, FG_OFF } = AnsiEscapeSequences;
return `${ FG_WHITE }${ text }${ FG_OFF }`;
}
}
22 changes: 20 additions & 2 deletions test/util/scale/scale-test-sets.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ import { Timer } from './timer.model';
* ```
*/
export abstract class ScaleTestSets {
private static hasFinishedCopyingMultiples = false;
private static hasFinishedCopyingMany = false;
private static copyingManyTimes = 0;

/* multiples of 1, contains (1 - 15M) */
public static readonly multiplesOf1 = ScaleTestSets.multiplesOf(1, 15_000_000);
Expand Down Expand Up @@ -63,15 +66,16 @@ export abstract class ScaleTestSets {
]);

private static multiplesOf(factor: number, size: number, offset = 0): ReadonlySet<number> {
return Timer.time('copying multiples', () =>
return Timer.time('copying sets', () =>
new Set<number>(Array.from(
{ length: size },
(_, index) => (index * factor) + offset),
));
}

private static manyOf(quantity: number, size: number, offset = false): ReadonlyArray<ReadonlySet<number>> {
return Timer.time('copying many', () =>
ScaleTestSets.incrementTimer();
return Timer.time('copying sets', () =>
Array.from(
{ length: quantity },
(_1, setIndex) => new Set<number>(Array.from(
Expand All @@ -80,6 +84,20 @@ export abstract class ScaleTestSets {
)),
));
}

private static incrementTimer(): void {
if (!ScaleTestSets.hasFinishedCopyingMultiples) {
ScaleTestSets.hasFinishedCopyingMultiples = true;
Timer.nextLine('copying sets');
}

if (!ScaleTestSets.hasFinishedCopyingMany) {
if (ScaleTestSets.copyingManyTimes++ === 4) {
ScaleTestSets.hasFinishedCopyingMany = true;
Timer.nextLine('copying sets');
}
}
}
}

Timer.logAll();
Loading

0 comments on commit fa81956

Please sign in to comment.