Add color coding to time output

This should make it easier to read how much each compiler stage took.

Signed-off-by: Slendi <slendi@socopon.com>
This commit is contained in:
Slendi 2024-05-04 13:43:28 +02:00
parent 5af9845f93
commit b22610a2b5

View File

@ -77,28 +77,31 @@ main :: proc() {
}
fmt.println("Time report")
fmt.println("===========")
fmt.println("\x1B[90m===========\x1B[0m")
most_printed := 0
printed := fmt.printf(
"Parsing took: % 10dns (%.3fms)\n",
"Parsing took: \x1B[93m% 10d\x1B[0m\x1B[96mns \x1B[90m(\x1B[92m%.3f\x1B[0m\x1B[96mms\x1B[90m)\x1B[0m\n",
time.duration_nanoseconds(parser_duration),
time.duration_milliseconds(parser_duration),
)
most_printed = max(printed, most_printed)
printed = fmt.printf(
"Type checker took: % 10dns (%.3fms)\n",
"Type checker took: \x1B[93m% 10d\x1B[0m\x1B[96mns \x1B[90m(\x1B[92m%.3f\x1B[0m\x1B[96mms\x1B[90m)\x1B[0m\n",
time.duration_nanoseconds(type_check_duration),
time.duration_milliseconds(type_check_duration),
)
most_printed = max(printed, most_printed)
llvm_duration: time.Duration = 0
defer {
fmt.printf("\x1B[90m")
most_printed -= 42
for most_printed > 1 {
fmt.printf("-")
most_printed -= 1
}
fmt.printf("\x1B[0m")
fmt.printf(
"\nTotal time: % 10dns (%.3fms)\n\n",
"\nTotal time: \x1B[93m% 10d\x1B[0m\x1B[96mns \x1B[90m(\x1B[92m%.3f\x1B[0m\x1B[96mms\x1B[90m)\x1B[0m\n\n",
time.duration_nanoseconds(llvm_duration + type_check_duration + parser_duration),
time.duration_milliseconds(llvm_duration + type_check_duration + parser_duration),
)
@ -137,7 +140,7 @@ main :: proc() {
generate_llvm(ctx, module, builder, ast)
llvm_duration = time.since(llvm_start)
printed = fmt.printf(
"LLVM generation took: % 10dns (%.3fms)\n",
"LLVM generation took: \x1B[93m% 10d\x1B[0m\x1B[96mns \x1B[90m(\x1B[92m%.3f\x1B[0m\x1B[96mms\x1B[90m)\x1B[0m\n",
time.duration_nanoseconds(llvm_duration),
time.duration_milliseconds(llvm_duration),
)