generated from yamiteru/ts-package
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
258 additions
and
206 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,46 @@ | ||
# TS Package | ||
|
||
Template for creating publishable TypeScript package. It uses SWC for compilation. | ||
|
||
## TODOs | ||
|
||
- [ ] Implement output mode | ||
|
||
- [ ] Add ability to stop benchmark execution after N ms | ||
- [ ] Add ability to stop benchmark execution after N iterations | ||
- [ ] Clean up and restructure/refactor the codebase | ||
- [ ] Figure out ways to optimize the lib | ||
- [ ] Optimize the code (the less users have to wait the better) | ||
- [ ] Create examples (should also work as tests) | ||
|
||
- [ ] Write docs | ||
- [ ] Compare this lib to other libs (definitely against benchmark.js) | ||
- [ ] Publish alpha version | ||
|
||
## Notes | ||
|
||
- It should probably have a static and interactive mode | ||
- Static mode should be the main focus | ||
- I should design TUI for the interactive mode | ||
|
||
## Interactive mode | ||
|
||
- Shows real-time data from all benchmark iterations | ||
- It should have different "screen" per each benchmark | ||
- I can switch between different screens | ||
- I should be able to also show all results in one big graph | ||
- I should be able to re-run a benchmark from the TUI | ||
- The re-run data should be merged instead of using the latest (maybe??) | ||
- The cold part should have different color from the hot results | ||
|
||
## Static mode | ||
|
||
- Shows real-time data but can't use keyboard | ||
- Doesn't show a graph, only the basic info | ||
- Should be clear what is happening and why is user waiting | ||
|
||
## Output mode | ||
|
||
- Outputs markdown into a file | ||
- Data should be in a table with all important data | ||
- If possible should generate SVG graphs and include them into the markdown file |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { Mode, Options } from "./types"; | ||
|
||
export function createStore(mode: Mode, options: Options) { | ||
return { | ||
array: new Uint32Array(new ArrayBuffer(options[mode].chunkSize * 4)), | ||
index: 0, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,15 @@ | ||
import { Options, Stores } from "./types"; | ||
import { createStore } from "./createStore"; | ||
import { Options } from "./types"; | ||
|
||
// memoize store by options and reuse it if possible | ||
export function createStores(options: Options): Stores { | ||
export function createStores(options: Options) { | ||
return { | ||
cpu: { | ||
chunk: { | ||
array: new Uint32Array(new ArrayBuffer(options.cpu.chunkSize * 4)), | ||
index: 0, | ||
}, | ||
main: { | ||
array: new Uint32Array(new ArrayBuffer(options.cpu.chunkSize * 4)), | ||
index: 0, | ||
}, | ||
chunk: createStore("cpu", options), | ||
main: createStore("cpu", options), | ||
}, | ||
ram: { | ||
chunk: { | ||
array: new Uint32Array(new ArrayBuffer(options.ram.chunkSize * 4)), | ||
index: 0, | ||
}, | ||
main: { | ||
array: new Uint32Array(new ArrayBuffer(options.ram.chunkSize * 4)), | ||
index: 0, | ||
}, | ||
chunk: createStore("ram", options), | ||
main: createStore("ram", options), | ||
}, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,15 @@ | ||
import { getOffset } from "./getOffset"; | ||
import { Offsets, Options, Stores } from "./types"; | ||
import { Offsets } from "./types"; | ||
|
||
export async function getAllOffsets( | ||
stores: Stores, | ||
options: Options, | ||
): Promise<Offsets> { | ||
export async function getAllOffsets(): Promise<Offsets> { | ||
return { | ||
async: { | ||
cpu: await getOffset({ type: "async", mode: "cpu" }, stores, options), | ||
ram: await getOffset({ type: "async", mode: "ram" }, stores, options), | ||
cpu: await getOffset({ type: "async", mode: "cpu" }), | ||
ram: await getOffset({ type: "async", mode: "ram" }), | ||
}, | ||
sync: { | ||
cpu: await getOffset({ type: "sync", mode: "cpu" }, stores, options), | ||
ram: await getOffset({ type: "sync", mode: "ram" }, stores, options), | ||
cpu: await getOffset({ type: "sync", mode: "cpu" }), | ||
ram: await getOffset({ type: "sync", mode: "ram" }), | ||
}, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,55 +1,44 @@ | ||
import { OFFSETS } from "./constants"; | ||
import { | ||
FN_ASYNC, | ||
FN_SYNC, | ||
OFFSET, | ||
OFFSETS, | ||
OFFSET_KEYS, | ||
OFFSET_MAX, | ||
} from "./constants"; | ||
import { run } from "./run"; | ||
import { OffsetData, Options, Stores } from "./types"; | ||
|
||
const KEYS = ["min", "max", "median"]; | ||
const MAX = KEYS.length; | ||
|
||
export async function getOffset( | ||
{ type, mode }: OffsetData, | ||
stores: Stores, | ||
options: Options, | ||
) { | ||
const fn = type === "async" | ||
? async () => { | ||
/* */ | ||
import { OffsetData } from "./types"; | ||
|
||
export async function getOffset({ type, mode }: OffsetData) { | ||
const fn = type === "async" ? FN_ASYNC : FN_SYNC; | ||
const result = { ...OFFSET }; | ||
|
||
while (true as any) { | ||
const offset = await run(fn, mode, OFFSETS); | ||
|
||
let counter = 0; | ||
|
||
for (let i = 0; i < OFFSET_MAX; ++i) { | ||
const key = OFFSET_KEYS[i]; | ||
|
||
if (result[key]) { | ||
const substracted = offset[key] - result[key]; | ||
|
||
if (substracted <= 0) { | ||
result[key] += offset[key] + substracted; | ||
counter += 1; | ||
} else { | ||
result[key] += offset[key]; | ||
} | ||
: () => { | ||
/* */ | ||
}; | ||
|
||
const result = { | ||
min: 0, | ||
max: 0, | ||
median: 0 | ||
}; | ||
|
||
while(true as any) { | ||
const offset = await run(fn, mode, stores, OFFSETS, options); | ||
|
||
let counter = 0; | ||
|
||
for(let i = 0; i < MAX; ++i) { | ||
const key = KEYS[i]; | ||
|
||
if(result[key]) { | ||
const substracted = offset[key] - result[key]; | ||
|
||
if(substracted <= 0) { | ||
result[key] += offset[key] + substracted; | ||
counter += 1; | ||
} else { | ||
result[key] += offset[key]; | ||
} | ||
} else { | ||
result[key] += offset[key]; | ||
} | ||
} | ||
|
||
if(counter === MAX) { | ||
break; | ||
} | ||
} | ||
|
||
return result; | ||
} else { | ||
result[key] += offset[key]; | ||
} | ||
} | ||
|
||
if (counter === OFFSET_MAX) { | ||
break; | ||
} | ||
} | ||
|
||
return result; | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,16 @@ | ||
import { preset } from "./preset"; | ||
import { printSuite } from "./printSuite"; | ||
|
||
const defaultSuite = preset(); | ||
const callibration = defaultSuite({ | ||
emptyAsync: async () => { | ||
/* */ | ||
test: () => { | ||
`${Math.random()}`; | ||
}, | ||
emptySync: () => { | ||
/* */ | ||
}, | ||
}); | ||
|
||
(async () => { | ||
for await (const result of callibration()) { | ||
console.log(result); | ||
} | ||
await printSuite(callibration); | ||
})(); |
Oops, something went wrong.