Skip to content

Commit

Permalink
apply review suggestion.
Browse files Browse the repository at this point in the history
  • Loading branch information
tzzed committed Feb 20, 2022
1 parent 3581006 commit 6f77506
Showing 1 changed file with 1 addition and 17 deletions.
18 changes: 1 addition & 17 deletions cmd/genji/shell/shell.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,29 +200,13 @@ func (sh *Shell) runExecutor(ctx context.Context, promptExecCh chan string) erro

// if showtime is true, ensure it's a query, and it was executed.
if showTime && !strings.HasPrefix(input, ".") && strings.HasSuffix(input, ";") {
displayTime(start)
fmt.Printf("Time: %s\n", time.Since(start))
}
case promptExecCh <- "":
}
}
}

// displayTime shows execution time of a query.
func displayTime(start time.Time) {
unit := "s"
multiplier := 1.0
precision := 3
completed := time.Since(start)
// under a second print in ms unit.
if completed.Seconds() < 1 {
unit = "ms"
multiplier = 1000.
precision = 0
}

fmt.Printf("Time: %.*f%s\n", precision, completed.Seconds()*multiplier, unit)
}

// runPrompt is a stateless function that displays a prompt to the user.
// User input is sent to the execCh channel which must deal with parsing and error handling.
// Once the execution of the user input is done by the reader of the channel, it must
Expand Down

0 comments on commit 6f77506

Please sign in to comment.