(c *cli.Context, configFile string)
| 23 | } |
| 24 | |
| 25 | func runJudgeBenchmark(c *cli.Context, configFile string) error { |
| 26 | rel := JudgementBenchmark{ |
| 27 | Counter: map[string]int{}, |
| 28 | } |
| 29 | |
| 30 | times := c.Int("benchmark") |
| 31 | rfp, err := os.OpenFile("./report.log", os.O_WRONLY|os.O_CREATE, 0644) |
| 32 | if err != nil { |
| 33 | return err |
| 34 | } |
| 35 | defer rfp.Close() |
| 36 | |
| 37 | workDir := c.String("work-dir") |
| 38 | // 构建运行选项 |
| 39 | rOptions := &JudgementRunOption{ |
| 40 | Clean: true, |
| 41 | ShowLog: false, |
| 42 | LogLevel: 0, |
| 43 | WorkDir: workDir, |
| 44 | ConfigFile: configFile, |
| 45 | Language: c.String("language"), |
| 46 | LibraryDir: c.String("library"), |
| 47 | CodePath: c.Args().Get(1), |
| 48 | SessionID: "", |
| 49 | SessionRoot: "", |
| 50 | } |
| 51 | |
| 52 | startTime := time.Now().UnixNano() |
| 53 | exitCounter := map[int]int{} |
| 54 | for i := 0; i < times; i++ { |
| 55 | if i%10 == 0 { |
| 56 | log.Printf("[%d / %d]\n", i, times) |
| 57 | } |
| 58 | judgeResult, _, err := runOnceJudge(rOptions) |
| 59 | if err != nil { |
| 60 | rel.Message = fmt.Sprintf("break! %s\n", err.Error()) |
| 61 | log.Print(rel.Message) |
| 62 | _, _ = rfp.WriteString(fmt.Sprintf("[%s]: %s\n", strconv.Itoa(i), err.Error())) |
| 63 | break |
| 64 | } |
| 65 | name, ok := constants.FlagMeansMap[judgeResult.JudgeResult] |
| 66 | if !ok { |
| 67 | name = "Unknown" |
| 68 | } |
| 69 | _, _ = rfp.WriteString(fmt.Sprintf("[%s]: %s\n", judgeResult.SessionID, name)) |
| 70 | if judgeResult.JudgeResult != constants.JudgeFlagAC { |
| 71 | _, _ = rfp.WriteString(utils.ObjectToJSONStringFormatted(judgeResult) + "\n") |
| 72 | } |
| 73 | exitCounter[judgeResult.JudgeResult]++ |
| 74 | } |
| 75 | endTime := time.Now().UnixNano() |
| 76 | for key, value := range exitCounter { |
| 77 | name, ok := constants.FlagMeansMap[key] |
| 78 | if !ok { |
| 79 | name = "Unknown" |
| 80 | } |
| 81 | rel.Counter[name] = value |
| 82 | log.Printf("%s: %d\n", name, value) |
no test coverage detected