Last active
March 8, 2023 20:56
-
-
Save schmichael/1a417808b8e88b684838ae9f4cd5d8be to your computer and use it in GitHub Desktop.
This file contains hidden or 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
package main | |
import ( | |
"fmt" | |
"sync" | |
"time" | |
) | |
func timeTasks(count int) time.Duration { | |
nopTask := func(done func()) { | |
done() | |
} | |
start := time.Now() | |
wg := &sync.WaitGroup{} | |
wg.Add(count) | |
for i := 0; i < count; i++ { | |
go nopTask(wg.Done) | |
} | |
wg.Wait() | |
return time.Now().Sub(start) | |
} | |
func main() { | |
for n := 100_000; n <= 1_000_000; n += 100_000 { | |
createTime := timeTasks(n) | |
createPerSecond := (1.0 / (float64(createTime) / float64(n))) * float64(time.Second) | |
fmt.Printf("%d tasks \t %f tasks per/s\n", n, createPerSecond) | |
} | |
} |
This file contains hidden or 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
from asyncio import create_task, wait, run | |
from time import process_time as time | |
async def time_tasks(count=100) -> float: | |
"""Time creating and destroying tasks.""" | |
async def nop_task() -> None: | |
"""Do nothing task.""" | |
pass | |
start = time() | |
tasks = [create_task(nop_task()) for _ in range(count)] | |
await wait(tasks) | |
elapsed = time() - start | |
return elapsed | |
for count in range(100_000, 1000_000 + 1, 100_000): | |
create_time = run(time_tasks(count)) | |
create_per_second = 1 / (create_time / count) | |
print(f"{count:,} tasks \t {create_per_second:0,.0f} tasks per/s") |
This file contains hidden or 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
~/src/tmp$ go run noop.go | |
100000 tasks 4259037.197792 tasks per/s | |
200000 tasks 4551146.581736 tasks per/s | |
300000 tasks 4195348.281732 tasks per/s | |
400000 tasks 4469904.124356 tasks per/s | |
500000 tasks 4656643.335021 tasks per/s | |
600000 tasks 4537211.875136 tasks per/s | |
700000 tasks 4537840.314605 tasks per/s | |
800000 tasks 4411617.281635 tasks per/s | |
900000 tasks 4591128.084704 tasks per/s | |
1000000 tasks 4572292.949041 tasks per/s | |
~/src/tmp$ python3 noop.py | |
100,000 tasks 180,894 tasks per/s | |
200,000 tasks 175,868 tasks per/s | |
300,000 tasks 179,956 tasks per/s | |
400,000 tasks 183,712 tasks per/s | |
500,000 tasks 173,246 tasks per/s | |
600,000 tasks 172,198 tasks per/s | |
700,000 tasks 182,499 tasks per/s | |
800,000 tasks 174,300 tasks per/s | |
900,000 tasks 165,227 tasks per/s | |
1,000,000 tasks 165,703 tasks per/s |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment