Skip to content

Commit 51fcf35

Browse files
committed
Refactor and enhance benchmarking script formatting.
Reformats code for better readability and adds a reusable `PrintLine` function to replace repeated horizontal line-printing logic. These changes improve code clarity and maintainability without altering functionality.
1 parent d8c8525 commit 51fcf35

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

demo/minimum/bench.lua

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ function SystemFamily()
2121
end
2222

2323
function BenchmarkStart(name, iterations)
24-
io.write(string.format("%-9s", name) .. "\t" .. string.format("%10s", iterations) .. "\t")
24+
io.write(string.format("%-9s", name) .. "\t" ..
25+
string.format("%10s", iterations) .. "\t")
2526
io.flush()
2627
return os.clock()
2728
end
@@ -141,13 +142,17 @@ local function benchmark_array()
141142
BenchmarkEnd(bm)
142143
end
143144

145+
local function PrintLine() print(string.rep('_', 49)) end
146+
144147
-- Some information
145148
print("Interpreter:", _VERSION)
146149
print("System Family:", SystemFamily())
147-
print("Memory Used:", string.format("%.3fkB", collectgarbage("count")))
150+
print("Memory Used:",
151+
string.format("%.3fkB", collectgarbage("count")))
148152
print("Minimum Int:", math.mininteger or "Unknown")
149153
print("Maximum Int:", math.maxinteger or "Unknown")
150154
print("\nBenchmark", "Iterations", "Time (min:sec.ms)")
155+
PrintLine()
151156

152157
-- Run the benchmarks
153158
bm = os.clock() -- Start the total time clock
@@ -161,7 +166,9 @@ benchmark_gcd()
161166
benchmark_array()
162167

163168
-- Print memory and total time summary at the end of the table
164-
print(string.rep('_', 49)) -- Print a horizontal line to separate results from final summary
165-
io.write("Total:\t\t" .. string.format("%8.3fkB", collectgarbage("count")) .. "\t")
169+
PrintLine()
170+
io.write("Total:\t\t" ..
171+
string.format("%8.3fkB", collectgarbage("count")) ..
172+
"\t")
166173
BenchmarkEnd(bm)
167174
print("Press Enter to Exit...") io.read() os.exit()

0 commit comments

Comments
 (0)