github.com/maruel/nin@v0.0.0-20220112143044-f35891e3ce7e/cmd/depfile_parser_perftest/depfile_parser_perftest.go (about) 1 // Copyright 2011 Google Inc. All Rights Reserved. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package main 16 17 import ( 18 "fmt" 19 "io/ioutil" 20 "os" 21 "time" 22 23 "github.com/maruel/nin" 24 ) 25 26 func main() { 27 if len(os.Args) < 2 { 28 fmt.Printf("usage: %s <file1> <file2...>\n", os.Args[0]) 29 os.Exit(1) 30 } 31 32 rnd := time.Microsecond 33 var times []time.Duration 34 for _, filename := range os.Args[1:] { 35 for limit := 1 << 10; limit < (1 << 20); limit *= 2 { 36 start := time.Now() 37 for rep := 0; rep < limit; rep++ { 38 buf, err := ioutil.ReadFile(filename) 39 if err != nil { 40 fmt.Printf("%s: %s\n", filename, err) 41 os.Exit(1) 42 } 43 44 parser := nin.DepfileParser{} 45 if err = parser.Parse(buf); err != nil { 46 fmt.Printf("%s: %s\n", filename, err) 47 os.Exit(1) 48 } 49 } 50 delta := time.Since(start) 51 52 if delta > 100*time.Millisecond { 53 time := delta / time.Duration(limit) 54 fmt.Printf("%s: %s\n", filename, time.Round(rnd)) 55 times = append(times, time) 56 break 57 } 58 } 59 } 60 61 if len(times) != 0 { 62 min := times[0] 63 max := times[0] 64 total := time.Duration(0) 65 for i := 0; i < len(times); i++ { 66 total += times[i] 67 if times[i] < min { 68 min = times[i] 69 } else if times[i] > max { 70 max = times[i] 71 } 72 } 73 74 avg := total / time.Duration(len(times)) 75 fmt.Printf("min %s max %s avg %s\n", min.Round(rnd), max.Round(rnd), avg.Round(rnd)) 76 } 77 }