hstt/main.py
def timing_stats(results: List[Result]) -> List[str]:
    """Calculate and format lines with timings across completed results."""
    def percentile(data: List[float], percent: int) -> Union[float, str]:
        if not data:
            return '-'
        data_sorted = sorted(data)
        pos = max(int(round(percent / 100 * len(data) + 0.5)), 2)
        return data_sorted[pos - 2]

    def format_line(name: str, *values: Union[float, int, str]) -> str:
        line = f'{name:<10s}'
        for value in values:
            if isinstance(value, float):
                line += f' {value:6.0f}'
            else:
                line += f' {value:>6}'
        return line

    total_times = [r.total_time * 1000 for r in results if r.total_time]
    ttfb_times = [r.ttfb_time * 1000 for r in results if r.ttfb_time]
    conn_times = [r.conn_time * 1000 for r in results if r.conn_time]

    percentiles = (50, 80, 95, 99)
    lines = [
        format_line(
            '', 'Mean', 'Min', *(f'{p}%' for p in percentiles), 'Max',
        ),
        format_line(
            'Connect:',
            mean(conn_times) if conn_times else '-',
            min(conn_times) if conn_times else '-',
            *(percentile(conn_times, p) for p in percentiles),
            max(conn_times) if conn_times else '-',
        ),
        format_line(
            'TTFB:',
            mean(ttfb_times) if ttfb_times else '-',
            min(ttfb_times) if ttfb_times else '-',
            *(percentile(ttfb_times, p) for p in percentiles),
            max(ttfb_times) if ttfb_times else '-',
        ),
        format_line(
            'Total:',
            mean(total_times) if total_times else '-',
            min(total_times) if total_times else '-',
            *(percentile(total_times, p) for p in percentiles),
            max(total_times) if total_times else '-',
        ),
    ]
    return lines
Calculate and format lines with timings across completed results.
Calculate and format lines with timings across completed results.
Calculate and format lines with timings across completed results .
def timing_stats(results: List[Result]) -> List[str]:
    def percentile(data: List[float], percent: int) -> Union[float, str]:
        if not data:
            return '-'
        data_sorted = sorted(data)
        pos = max(int(round(percent / 100 * len(data) + 0.5)), 2)
        return data_sorted[pos - 2]
    def format_line(name: str, *values: Union[float, int, str]) -> str:
        line = f'{name:<10s}'
        for value in values:
            if isinstance(value, float):
                line += f' {value:6.0f}'
            else:
                line += f' {value:>6}'
        return line
    total_times = [r.total_time * 1000 for r in results if r.total_time]
    ttfb_times = [r.ttfb_time * 1000 for r in results if r.ttfb_time]
    conn_times = [r.conn_time * 1000 for r in results if r.conn_time]
    percentiles = (50, 80, 95, 99)
    lines = [
        format_line(
            '', 'Mean', 'Min', *(f'{p}%' for p in percentiles), 'Max',
        ),
        format_line(
            'Connect:',
            mean(conn_times) if conn_times else '-',
            min(conn_times) if conn_times else '-',
            *(percentile(conn_times, p) for p in percentiles),
            max(conn_times) if conn_times else '-',
        ),
        format_line(
            'TTFB:',
            mean(ttfb_times) if ttfb_times else '-',
            min(ttfb_times) if ttfb_times else '-',
            *(percentile(ttfb_times, p) for p in percentiles),
            max(ttfb_times) if ttfb_times else '-',
        ),
        format_line(
            'Total:',
            mean(total_times) if total_times else '-',
            min(total_times) if total_times else '-',
            *(percentile(total_times, p) for p in percentiles),
            max(total_times) if total_times else '-',
        ),
    ]
    return lines
def timing_stats ( results : List [ Result ] ) -> List [ str ] : def percentile ( data : List [ float ] , percent : int ) -> Union [ float , str ] : if not data : return '-' data_sorted = sorted ( data ) pos = max ( int ( round ( percent / 100 * len ( data ) + 0.5 ) ) , 2 ) return data_sorted [ pos - 2 ] def format_line ( name : str , * values : Union [ float , int , str ] ) -> str : line = f'{name:<10s}' for value in values : if isinstance ( value , float ) : line += f' {value:6.0f}' else : line += f' {value:>6}' return line total_times = [ r . total_time * 1000 for r in results if r . total_time ] ttfb_times = [ r . ttfb_time * 1000 for r in results if r . ttfb_time ] conn_times = [ r . conn_time * 1000 for r in results if r . conn_time ] percentiles = ( 50 , 80 , 95 , 99 ) lines = [ format_line ( '' , 'Mean' , 'Min' , * ( f'{p}%' for p in percentiles ) , 'Max' , ) , format_line ( 'Connect:' , mean ( conn_times ) if conn_times else '-' , min ( conn_times ) if conn_times else '-' , * ( percentile ( conn_times , p ) for p in percentiles ) , max ( conn_times ) if conn_times else '-' , ) , format_line ( 'TTFB:' , mean ( ttfb_times ) if ttfb_times else '-' , min ( ttfb_times ) if ttfb_times else '-' , * ( percentile ( ttfb_times , p ) for p in percentiles ) , max ( ttfb_times ) if ttfb_times else '-' , ) , format_line ( 'Total:' , mean ( total_times ) if total_times else '-' , min ( total_times ) if total_times else '-' , * ( percentile ( total_times , p ) for p in percentiles ) , max ( total_times ) if total_times else '-' , ) , ] return lines
Calculate and format lines with timings across completed results.
Calculate and format lines with timings across completed results .
"""Calculate and format lines with timings across completed results."""
results
List[Result]