Skip to content

Commit

Permalink
v2.4 publish
Browse files Browse the repository at this point in the history
  • Loading branch information
samchon committed Jan 6, 2020
1 parent 9630395 commit 31b4823
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"email": "samchon@samchon.org",
"url": "http://samchon.org"
},
"version": "2.4.0-dev.20200105",
"version": "2.4.0",
"main": "./index.js",
"typings": "./index.d.ts",
"scripts": {
Expand Down
File renamed without changes.
9 changes: 9 additions & 0 deletions src/benchmark/internal/TimeWatch.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export namespace TimeWatch
{
export function measure(proc: ()=>void): number
{
let time: number = Date.now();
proc();
return Date.now() - time;
}
}
41 changes: 41 additions & 0 deletions src/benchmark/sorts.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { Vector } from "../container/Vector";
import { Deque } from "../container/Deque";

import { StringUtil } from "./internal/StringUtil";
import { TimeWatch } from "./internal/TimeWatch";

import { randint } from "../algorithm/random";
import { sort } from "../ranges/algorithm/sorting";

function watch(n: number): [number, number, number]
{
let items: number[] = [];
for (let i: number = 0; i < n; ++i)
items.push(randint(1, n));

let v: Vector<number> = new Vector(items);
let d: Deque<number> = new Deque(items);

return [
TimeWatch.measure(() => items.sort((x, y) => x - y)),
TimeWatch.measure(() => sort(v)),
TimeWatch.measure(() => sort(d))
];
}

export async function main(): Promise<string>
{
let ret: string = "## Sorts \n"
+ " N | Array | Vector | Deque \n"
+ "---|-------|--------|-------\n";

for (let n of [1000, 10000, 100000])
{
let line: string = StringUtil.numberFormat(n);
for (let time of watch(n))
line += ` | ${StringUtil.numberFormat(time)}`;

ret += line + "\n";
}
return ret;
}
2 changes: 1 addition & 1 deletion src/test/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as fs from "fs";
import { StringUtil } from "./internal/StringUtil";
import { StringUtil } from "../benchmark/internal/StringUtil";

const PATH = __dirname;

Expand Down

0 comments on commit 31b4823

Please sign in to comment.