dmd -run speed trends
Witold Baryluk
witold.baryluk at gmail.com
Thu Dec 7 20:39:03 UTC 2023
On Thursday, 7 December 2023 at 16:32:32 UTC, Witold Baryluk
wrote:
> dmd
Inspecting output of `dmd -v`, shows that a lot of time is spend
on various helpers of `writefln`. Changing `writefln` to
`writeln` (and adjusting things so the output is still the same),
speeds things a lot:
729.5 ms -> 431.8 ms (dmd 2.106.0)
896.6 ms -> 638.7 (dmd 2.098.1)
Considering that most script like programs will need to do some
IO, `writefln` looks a little bloated (slow to compile). Having
string interpolation would probably help a little, but even then
431 ms is not that great.
Also for completeness, golang:
go1.21.4 121 ms
This is using `go run`.
Way faster.
```go
package main
import (
"fmt"
"strings"
)
type Person struct {
name string
age int
}
var people = []Person{
Person{name: "John", age: 45},
Person{name: "Kate", age: 30},
}
func oddNumbers(a []int) chan int {
ch := make(chan int)
go func() {
for _, x := range a {
if x%2 == 0 {
continue
}
ch <- x
}
close(ch)
}()
return ch
}
func toLookupTable(data string) map[string]bool {
result := make(map[string]bool)
for _, w := range strings.Split(data, ";") {
result[w] = true
}
return result
}
func main() {
for _, person := range people {
fmt.Printf("%s is %d years old\n", person.name, person.age)
}
for odd := range oddNumbers([]int{3, 6, 9, 12, 15, 18}) {
fmt.Printf("%d\n", odd)
}
data := "mov;btc;cli;xor;afoo"
opcodes := toLookupTable(data)
for o := range opcodes {
fmt.Printf("%s\n", o)
}
}
```
More information about the Digitalmars-d
mailing list