mirror of
https://github.com/johnkerl/miller.git
synced 2026-01-23 02:14:13 +00:00
Improve type-inference performance (#809)
* To-do items for broader platform/go-version benchmarking * neaten inferrer API * extend type-inference unit-test cases * Add benchmark scripts for comparing compiler versions * mlr version in addition to mlr --version * some go-benchmark files for Mac/Linux perf comparisons * neaten perf-scripts * merge * type-scan optimization tests * type-scan optimization infra * test new inferrer * mlr --time option * include --cpuprofile and --traceprofile in on-line help * sharpen inferred/deferred-type API distinction * replace old inferrer with newer/faster * update docs for new type-inferrer
This commit is contained in:
parent
5e8d3fddd0
commit
e10fee0724
47 changed files with 1595 additions and 381 deletions
|
|
@ -8,12 +8,16 @@ import (
|
|||
"runtime/debug"
|
||||
"runtime/pprof"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/johnkerl/miller/internal/pkg/entrypoint"
|
||||
"github.com/pkg/profile" // for trace.out
|
||||
)
|
||||
|
||||
func main() {
|
||||
// For mlr --time
|
||||
startTime := time.Now()
|
||||
|
||||
// Respect env $GOMAXPROCS, if provided, else set default.
|
||||
haveSetGoMaxProcs := false
|
||||
|
|
@ -63,12 +67,35 @@ func main() {
|
|||
defer fmt.Fprintf(os.Stderr, "CPU profile finished.\ngo tool pprof -http=:8080 %s\n", profFilename)
|
||||
}
|
||||
|
||||
if len(os.Args) >= 3 && os.Args[1] == "--traceprofile" {
|
||||
if len(os.Args) >= 2 && os.Args[1] == "--traceprofile" {
|
||||
defer profile.Start(profile.TraceProfile, profile.ProfilePath(".")).Stop()
|
||||
defer fmt.Fprintf(os.Stderr, "go tool trace trace.out\n")
|
||||
}
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
// This will obtain os.Args and go from there. All the usual contents of
|
||||
// main() are put into this package for ease of testing.
|
||||
entrypoint.Main()
|
||||
mainReturn := entrypoint.Main()
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
// Timing
|
||||
//
|
||||
// The system 'time' command is built-in, of course but it's nice to have
|
||||
// simply wall-time without the real/user/sys distinction. Also, making
|
||||
// this a Miller built-in is nice for Windows.
|
||||
if mainReturn.PrintElapsedTime {
|
||||
endTime := time.Now()
|
||||
startNanos := startTime.UnixNano()
|
||||
endNanos := endTime.UnixNano()
|
||||
seconds := float64(endNanos-startNanos) / 1e9
|
||||
fmt.Fprintf(os.Stderr, "%.6f", seconds)
|
||||
for _, arg := range os.Args {
|
||||
if strings.Contains(arg, " ") || strings.Contains(arg, "\t") {
|
||||
fmt.Fprintf(os.Stderr, " '%s'", arg)
|
||||
} else {
|
||||
fmt.Fprintf(os.Stderr, " %s", arg)
|
||||
}
|
||||
}
|
||||
fmt.Fprintf(os.Stderr, "\n")
|
||||
}
|
||||
}
|
||||
|
|
|
|||
19
cmd/scan/main.go
Normal file
19
cmd/scan/main.go
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
// ================================================================
|
||||
// Experiments for type-inference performance optimization
|
||||
// ================================================================
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/johnkerl/miller/internal/pkg/scan"
|
||||
)
|
||||
|
||||
func main() {
|
||||
for _, arg := range os.Args[1:] {
|
||||
scanType := scan.FindScanType(arg)
|
||||
fmt.Printf("%-10s -> %s\n", arg, scan.TypeNames[scanType])
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue