Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve AsyncPool.test.ts speed #345

Merged
merged 1 commit into from
Aug 1, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 14 additions & 14 deletions test/asyncpool.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,72 +13,72 @@ suite("AsyncPool Tests", () => {
test("Counting, Low Worker Count", async () => {
let pool = new AsyncPool(2);
let counter = 0;
for (let i = 0; i < 10000; i++) {
for (let i = 0; i < 1000; i++) {
pool.addTask(async () => {
counter++;
});
}
await pool.runAll();
assert.equal(counter, 10000);
assert.equal(counter, 1000);
})

test("Counting, High Worker Count", async () => {
let pool = new AsyncPool(300);
let counter = 0;
for (let i = 0; i < 10000; i++) {
for (let i = 0; i < 1000; i++) {
pool.addTask(async () => {
counter++;
});
}
await pool.runAll();
assert.equal(counter, 10000);
assert.equal(counter, 1000);
})

test("Counting, Resonable Worker Count", async () => {
let pool = new AsyncPool(10);
let counter = 0;
for (let i = 0; i < 10000; i++) {
for (let i = 0; i < 1000; i++) {
pool.addTask(async () => {
counter++;
});
}
await pool.runAll();
assert.equal(counter, 10000);
assert.equal(counter, 1000);
})

test("Timer, Random 1-6 ms tests", async () => {
let pool = new AsyncPool(8);
let counter = 0;
for (let i = 0; i < 1000; i++) {
for (let i = 0; i < 500; i++) {
pool.addTask(async () => {
await sleep(Math.random() * 6);
counter++;
});
}
await pool.runAll();
assert.equal(counter, 1000);
assert.equal(counter, 500);
});

test("Timer, 5ms , High Worker Count", async () => {
let pool = new AsyncPool(300);
let counter = 0;
for (let i = 0; i < 10000; i++) {
for (let i = 0; i < 100; i++) {
pool.addTask(async () => {
await sleep(5);
counter++;
});
}
await pool.runAll();
assert.equal(counter, 10000);
assert.equal(counter, 100);
});

test("Empty array", async () => {
let pool = new AsyncPool(8);
let arr = [];
for (let i = 0; i < 30000; i++) {
for (let i = 0; i < 300; i++) {
arr.push('testData' + i);
}
for (let i = 0; i < 30000; i++) {
for (let i = 0; i < 300; i++) {
pool.addTask(async () => {
arr.pop();
});
Expand All @@ -91,10 +91,10 @@ suite("AsyncPool Tests", () => {
let pool = new AsyncPool(8);
let arr: number[] = [];
let arr2: number[] = [];
for (let i = 0; i < 30000; i++) {
for (let i = 0; i < 300; i++) {
arr.push(i);
}
for (let i = 0; i < 30000; i++) {
for (let i = 0; i < 300; i++) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like some iterations were shrunk to 1/10, some to 1/2, and some to 1/100.
Was this from experimentation or heuristic that guided this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just getting them all to a reasonable time. Some have built-in delays.

pool.addTask(async () => {
arr2.push(i);
});
Expand Down