Measure the startup overhead of different programming languages
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Add redo.py

iacore 57718d43 7f2e1163

+152 -29
+142
redo.py
··· 1 + #!/usr/bin/env python 2 + 3 + """ 4 + A model of dependency graph. A build system. 5 + 6 + ## Features 7 + 8 + - [X] a rule can have multiple output files 9 + - [ ] run rules lazily 10 + - [X] allow a rule to compute its inputs on startup (already possible with computed property getter) 11 + - [ ] clean files 12 + """ 13 + 14 + import abc 15 + 16 + class Rule(abc.ABC): 17 + input: list[str] 18 + output: list[str] 19 + 20 + def __init_subclass__(rule, **kwargs): 21 + assert isinstance(rule.input, list), "input must be list[str]" 22 + assert isinstance(rule.output, list), "output must be list[str]" 23 + super().__init_subclass__(**kwargs) 24 + register(rule) 25 + 26 + @abc.abstractclassmethod 27 + def build(rule): pass 28 + 29 + 30 + def register(rule: Rule): 31 + rule.build() # todo 32 + 33 + def main(): 34 + # todo 35 + pass 36 + 37 + ## above is build system 38 + ## below is build definition 39 + 40 + import os 41 + from subprocess import run 42 + 43 + 44 + class _rule_amd64_asm(Rule): 45 + input = [ 'true.s' ] 46 + output = [ './true-s', 'true.o' ] 47 + 48 + @classmethod 49 + def build(rule): 50 + run(["nasm", "-f", "elf64", rule.input[0]]) 51 + run(["ld", "-o", rule.output[0], rule.output[1]]) 52 + 53 + 54 + class _rule_c(Rule): 55 + input = [ 'true.c' ] 56 + output = [ './true-c' ] 57 + 58 + @classmethod 59 + def build(rule): 60 + run(["gcc", "-O3", "-o", rule.output[0], rule.input[0]]) 61 + 62 + 63 + class _rule_zig(Rule): 64 + input = [ 'true.zig' ] 65 + output = [ './true-zig' ] 66 + 67 + @classmethod 68 + def build(rule): 69 + run(["zig", "build-exe", "-femit-bin=" + rule.output[0], "-O", "ReleaseFast", rule.input[0]]) 70 + 71 + 72 + class _rule_hare(Rule): 73 + input = [ 'true.ha' ] 74 + output = [ './true-hare' ] 75 + 76 + @classmethod 77 + def build(rule): 78 + run(["hare", "build", "-o", rule.output[0], "-F", "-R", rule.input[0]]) 79 + 80 + 81 + class _rule_go(Rule): 82 + input = [ 'true.go' ] 83 + output = [ './true-go' ] 84 + 85 + @classmethod 86 + def build(rule): 87 + run(["go", "build", "-o", rule.output[0], rule.input[0]]) 88 + 89 + 90 + class _rule_lean(Rule): 91 + input = [ 'True.lean' ] 92 + output = [ './true-lean', 'True.c' ] 93 + 94 + @classmethod 95 + def build(rule): 96 + run(["lean", "-c" + rule.output[1], rule.input[0]]) 97 + run(["leanc", "-O3", "-o", rule.output[0], rule.output[1]]) 98 + 99 + 100 + class _rule_haskell(Rule): 101 + input = [ 'True.hs' ] 102 + output = [ './true-haskell' ] 103 + 104 + @classmethod 105 + def build(rule): 106 + run(["ghc", rule.input[0], "-o", rule.output[0], "-O"]) 107 + 108 + 109 + class _rule_rust(Rule): 110 + input = [ 'true.rs' ] 111 + output = [ './true-rust' ] 112 + 113 + @classmethod 114 + def build(rule): 115 + run(["rustc", "-O", "-o", rule.output[0], rule.input[0]]) 116 + 117 + 118 + class _rule_d(Rule): 119 + input = [ 'true.d' ] 120 + output = [ './true-d' ] 121 + 122 + @classmethod 123 + def build(rule): 124 + run(["dmd", "-O", "-of=" + rule.output[0], rule.input[0]]) 125 + 126 + 127 + class _rule_pony(Rule): 128 + input = [ 'true.pony' ] 129 + output = [ './true-pony' ] 130 + 131 + @classmethod 132 + def build(rule): 133 + run(["ponyc", "-b", rule.output[0], "."]) 134 + 135 + 136 + class _rule_timings(Rule): 137 + input = [ './true-s', './true-c', './true-zig', './true-hare', './true-go', './true-lean', './true-haskell', './true-rust', './true-d', './true-pony' ] 138 + output = ["timings.md"] 139 + 140 + @classmethod 141 + def build(rule): 142 + run(["hyperfine", "--export-markdown", rule.output[0], "-N", *rule.input])
-27
run-all
··· 1 - #!/usr/bin/fish 2 - 3 - nasm -f elf64 true.s 4 - ld -o true-s true.o 5 - 6 - gcc -O3 -o true-c true.c 7 - 8 - zig build-exe -femit-bin=true-zig -O ReleaseFast true.zig 9 - 10 - hare build -o true-hare -F -R true.ha 11 - 12 - go build -o true-go true.go 13 - 14 - lean -cTrue.c True.lean 15 - leanc -O3 -o true-lean True.c 16 - 17 - ghc True.hs -o true-haskell -O 18 - 19 - rustc -O -o true-rust true.rs 20 - 21 - dmd -O -of=true-d true.d 22 - 23 - ponyc -b true-pony . 24 - 25 - hyperfine --export-markdown timings.md -N 'true' './true-s' './true-c' './true-zig' './true-hare' './true-go' './true-lean' './true-haskell' './true-rust' './true-d' './true-pony' 26 - 27 - # hyperfine --export-markdown timings.md -N './true-s' './true-zig' './true-hare' './true-d'
+10 -2
timings.md
··· 1 1 | Command | Mean [µs] | Min [µs] | Max [µs] | Relative | 2 2 |:---|---:|---:|---:|---:| 3 - | `true` | 271.6 ± 33.3 | 236.5 | 2069.0 | 3.41 ± 0.75 | 4 - | `./true-s` | 79.7 ± 14.5 | 70.7 | 462.8 | 1.00 | 3 + | `./true-s` | 82.9 ± 15.9 | 73.1 | 495.3 | 1.00 | 4 + | `./true-c` | 265.2 ± 27.2 | 230.5 | 476.8 | 3.20 ± 0.69 | 5 + | `./true-zig` | 88.6 ± 20.7 | 77.7 | 1949.8 | 1.07 ± 0.32 | 6 + | `./true-hare` | 95.1 ± 16.9 | 83.9 | 473.2 | 1.15 ± 0.30 | 7 + | `./true-go` | 585.4 ± 147.6 | 487.9 | 9621.9 | 7.06 ± 2.24 | 8 + | `./true-lean` | 1791.1 ± 579.1 | 1521.4 | 10884.6 | 21.61 ± 8.12 | 9 + | `./true-haskell` | 681.3 ± 34.3 | 616.1 | 979.6 | 8.22 ± 1.63 | 10 + | `./true-rust` | 392.6 ± 30.2 | 345.2 | 654.8 | 4.74 ± 0.98 | 11 + | `./true-d` | 526.6 ± 516.7 | 441.2 | 9601.8 | 6.35 ± 6.35 | 12 + | `./true-pony` | 2637.4 ± 588.3 | 2335.5 | 11624.2 | 31.82 ± 9.35 |