Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
Comment: | add 'spinner' example from Go Programming Language ch8 golang works 2.18x as hard (perf stat cycle count) to take 2.31x times as long (hyperfine runtime) as spinner.gdc. |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA3-256: |
40a2744c9df607bd1fe7651297e0cca6 |
User & Date: | admin 2021-10-30 19:24:22 |
Context
2021-10-30
| ||
19:55 | add Concurrent Clock Server example from Go Programming Language check-in: 5b30d6891f user: admin tags: trunk | |
19:24 | add 'spinner' example from Go Programming Language ch8 golang works 2.18x as hard (perf stat cycle count) to take 2.31x times as long (hyperfine runtime) as spinner.gdc. check-in: 40a2744c9d user: admin tags: trunk | |
18:58 | s/info/alert/ so that non-debug runs have output check-in: aabb260b80 user: admin tags: trunk | |
Changes
Added par/1-spinner/Makefile.
> > > > > > > > > > > > > > > > > > > > > > > > |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
ALL=golang/spinner spinner.dmd spinner.ldc spinner.gdc all:: $(ALL) bench:: $(ALL) PATH=$$PATH:. hyperfine $(ALL) clean:: rm -fv $(ALL) spinner.o stat:: $(ALL) for x in $(ALL); do perf stat ./$$x; done golang/spinner: ( cd golang; go build ) spinner.dmd: spinner.d dmd -O -release -of=$@ $< spinner.ldc: spinner.d ldc2 -O3 -release --of=$@ $< spinner.gdc: spinner.d gdc -O3 -frelease -o $@ $< |
Added par/1-spinner/bench.txt.
> > > > > > > > > > > > > > > > > > > > > |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
Benchmark #1: golang/spinner Time (mean ± σ): 5.296 s ± 0.175 s [User: 5.296 s, System: 0.005 s] Range (min … max): 5.120 s … 5.657 s 10 runs Benchmark #2: spinner.dmd Time (mean ± σ): 7.364 s ± 0.110 s [User: 7.356 s, System: 0.001 s] Range (min … max): 7.202 s … 7.520 s 10 runs Benchmark #3: spinner.ldc Time (mean ± σ): 4.009 s ± 0.137 s [User: 3.997 s, System: 0.003 s] Range (min … max): 3.836 s … 4.256 s 10 runs Benchmark #4: spinner.gdc Time (mean ± σ): 2.710 s ± 0.159 s [User: 2.702 s, System: 0.001 s] Range (min … max): 2.444 s … 2.954 s 10 runs Summary 'spinner.gdc' ran 1.48 ± 0.10 times faster than 'spinner.ldc' 1.95 ± 0.13 times faster than 'golang/spinner' 2.72 ± 0.16 times faster than 'spinner.dmd' |
Added par/1-spinner/golang/go.mod.
> > > |
1 2 3 |
module how.annoying/spinner go 1.17 |
Added par/1-spinner/golang/main.go.
> > > > > > > > > > > > > > > > > > > > > > > > > > > > > |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
package main import ( "fmt" "time" ) func main() { go spinner(100 * time.Millisecond) const n = 45 fibN := fib(n) // slow fmt.Printf("\rFibonacci(%d) = %d\n", n, fibN) } func spinner(delay time.Duration) { for { for _, r := range `-\|/` { fmt.Printf("\r%c", r) time.Sleep(delay) } } } func fib(x int) int { if x < 2 { return x } return fib(x-1) + fib(x-2) } |
Added par/1-spinner/spinner.d.
> > > > > > > > > > > > > > > > > > > > > > > > > > > |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
import std.stdio; import std.concurrency; import core.thread; void main() { spawnLinked(&spinner, 100.msecs); enum n = 45; auto fibN = fib(n); // slow writefln!"\rFibonacci(%d) = %d"(n, fibN); } void spinner(const Duration delay) { while (true) { bool done; foreach (r; `-\|/`) { writef!"\r%c"(r); stdout.flush; receiveTimeout(delay, (OwnerTerminated msg) { done = true; }); if (done) return; } } } int fib(int x) pure { return x < 2 ? x : fib(x - 1) + fib(x - 2); } |
Added par/1-spinner/stat.txt.
> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
Fibonacci(45) = 1134903170 Performance counter stats for './golang/spinner': 5,853.57 msec task-clock:u # 1.002 CPUs utilized 0 context-switches:u # 0.000 /sec 0 cpu-migrations:u # 0.000 /sec 205 page-faults:u # 35.021 /sec 19,836,216,150 cycles:u # 3.389 GHz 56,927,837,307 instructions:u # 2.87 insn per cycle 14,690,952,736 branches:u # 2.510 G/sec 2,687,390 branch-misses:u # 0.02% of all branches 5.841034408 seconds time elapsed 5.827126000 seconds user 0.023299000 seconds sys Fibonacci(45) = 1134903170 Performance counter stats for './spinner.dmd': 7,628.57 msec task-clock:u # 0.995 CPUs utilized 0 context-switches:u # 0.000 /sec 0 cpu-migrations:u # 0.000 /sec 163 page-faults:u # 21.367 /sec 27,026,046,662 cycles:u # 3.543 GHz 58,763,297,167 instructions:u # 2.17 insn per cycle 12,854,444,203 branches:u # 1.685 G/sec 5,357,377 branch-misses:u # 0.04% of all branches 7.664871367 seconds time elapsed 7.619882000 seconds user 0.003326000 seconds sys Fibonacci(45) = 1134903170 Performance counter stats for './spinner.ldc': 4,091.92 msec task-clock:u # 1.000 CPUs utilized 0 context-switches:u # 0.000 /sec 0 cpu-migrations:u # 0.000 /sec 258 page-faults:u # 63.051 /sec 14,416,152,694 cycles:u # 3.523 GHz 41,545,310,014 instructions:u # 2.88 insn per cycle 8,048,582,860 branches:u # 1.967 G/sec 57,437,145 branch-misses:u # 0.71% of all branches 4.090725336 seconds time elapsed 4.088798000 seconds user 0.000000000 seconds sys Fibonacci(45) = 1134903170 Performance counter stats for './spinner.gdc': 2,516.31 msec task-clock:u # 0.994 CPUs utilized 0 context-switches:u # 0.000 /sec 0 cpu-migrations:u # 0.000 /sec 209 page-faults:u # 83.058 /sec 9,088,458,833 cycles:u # 3.612 GHz 28,792,713,753 instructions:u # 3.17 insn per cycle 4,167,529,726 branches:u # 1.656 G/sec 14,487,088 branch-misses:u # 0.35% of all branches 2.531855027 seconds time elapsed 2.505587000 seconds user 0.009918000 seconds sys |