diff --git a/README.md b/README.md index e604378..172745e 100644 --- a/README.md +++ b/README.md @@ -89,3 +89,81 @@ Histogram for exit_time_ms [ 15.146, 15.808): * [ 15.808, 16.469]: ** ``` + +# Logarithmic Mode +**Note:** This is particularly useful for large `--iters` sizes. +``` +Settings +creates_tty = 0 +has_compsys = 1 +has_syntax_highlighting = 1 +has_autosuggestions = 1 +has_git_prompt = 1 + +Benchmark min_value, median_value, max_value +first_prompt_lag_ms = 11.678, 13.438, 22.217 +first_command_lag_ms = 115.986, 120.724, 158.821 +command_lag_ms = 11.206, 15.480, 18.518 +input_lag_ms = 12.002, 12.424, 13.451 +exit_time_ms = 9.855, 11.861, 16.469 + +Histogram for first_prompt_lag_ms +[ 11.678, 12.732): ***** +[ 12.732, 13.786): ****** +[ 13.786, 14.840): ***** +[ 14.840, 15.894): *** +[ 15.894, 16.947): ** +[ 16.947, 18.001): ** +[ 18.001, 19.055): ** +[ 19.055, 20.109): +[ 20.109, 21.163): * +[ 21.163, 22.217]: * + +Histogram for first_command_lag_ms +[ 115.986, 120.270): ****** +[ 120.270, 124.553): ***** +[ 124.553, 128.837): **** +[ 128.837, 133.120): *** +[ 133.120, 137.404): *** +[ 137.404, 141.687): ** +[ 141.687, 145.970): ** +[ 145.970, 150.254): * +[ 150.254, 154.537): * +[ 154.537, 158.821]: * + +Histogram for command_lag_ms +[ 11.206, 11.937): * +[ 11.937, 12.668): +[ 12.668, 13.400): +[ 13.400, 14.131): * +[ 14.131, 14.862): **** +[ 14.862, 15.593): ****** +[ 15.593, 16.324): ***** +[ 16.324, 17.056): **** +[ 17.056, 17.787): *** +[ 17.787, 18.518]: ** + +Histogram for input_lag_ms +[ 12.002, 12.147): **** +[ 12.147, 12.292): ***** +[ 12.292, 12.437): ***** +[ 12.437, 12.582): ***** +[ 12.582, 12.727): ***** +[ 12.727, 12.871): *** +[ 12.871, 13.016): +[ 13.016, 13.161): * +[ 13.161, 13.306): +[ 13.306, 13.451]: ** + +Histogram for exit_time_ms +[ 9.855, 10.516): **** +[ 10.516, 11.178): ***** +[ 11.178, 11.839): **** +[ 11.839, 12.501): ***** +[ 12.501, 13.162): ***** +[ 13.162, 13.823): *** +[ 13.823, 14.485): *** +[ 14.485, 15.146): ** +[ 15.146, 15.808): * +[ 15.808, 16.469]: ** +``` diff --git a/zsh-bench-hist.py b/zsh-bench-hist.py index ac261ae..db4b1c6 100644 --- a/zsh-bench-hist.py +++ b/zsh-bench-hist.py @@ -3,6 +3,7 @@ """This application processes the output of `zsh-bench --raw` to visualize it as ASCII histograms.""" import argparse +import math import re import sys import statistics @@ -56,7 +57,7 @@ def display_histogram(histogram: list, bin_width: float, min_value: float = 0.0, print(f'[{bin_start:{float_format}}, {bin_end:{float_format}}{interval_closing_brace}:', bar) -def display_timing_histograms(timings: dict, bin_count: int): +def display_timing_histograms(timings: dict, bin_count: int, logarithmic: bool): """Visualize the timings as textual histogram each.""" for name, values in timings.items(): print(f'Histogram for {name}') @@ -65,11 +66,15 @@ def display_timing_histograms(timings: dict, bin_count: int): bin_width = (max_value - min_value) / bin_count histogram = generate_histogram(data=values, bin_count=bin_count, min_value=min_value, bin_width=bin_width) + + if logarithmic: + histogram = [math.ceil(math.log(x+1, 2)) for x in histogram] + display_histogram(histogram, min_value=min_value, bin_width=bin_width) print() -def display_timings(timings: dict, bin_count: int): +def display_timings(timings: dict, bin_count: int, logarithmic: bool = False): """Display the settings and visualize the timings as textual histogram each.""" constants = ['creates_tty', 'has_compsys', 'has_syntax_highlighting', 'has_autosuggestions', 'has_git_prompt'] table_width = max(map(len, timings.keys())) # calculate width for formatting the table @@ -93,19 +98,20 @@ def display_timings(timings: dict, bin_count: int): print_metric_info(metric, min_value, median_value, max_value, width=table_width) print() - display_timing_histograms(timings, bin_count=bin_count) + display_timing_histograms(timings, bin_count=bin_count, logarithmic=logarithmic) def main(): """Parse zsh-bench data from stdin, Display the settings, and Visualize the timings as textual histogram each.""" parser = argparse.ArgumentParser(description='Visualizer of zsh-bench --raw output') - parser.add_argument('--bin-count', type=int, default=10, - help='Histogram bin count (default: 10, minimum: 1), optional') + parser.add_argument('--bin-count', type=int, default=10, help='Histogram bin count (default: 10, minimum: 1).') + parser.add_argument('--logarithmic', action='store_true', help='Use logarithmic histogram mode.') + args = parser.parse_args() command_output = sys.stdin.read() timings = extract_timings(command_output) - display_timings(timings=timings, bin_count=args.bin_count) + display_timings(timings=timings, bin_count=args.bin_count, logarithmic=args.logarithmic) if __name__ == '__main__':