Skip to content

Instantly share code, notes, and snippets.

@pwm
Created March 16, 2024 16:01
Show Gist options
  • Select an option

  • Save pwm/35d2f0c2895d1a7175f01a431bc62612 to your computer and use it in GitHub Desktop.

Select an option

Save pwm/35d2f0c2895d1a7175f01a431bc62612 to your computer and use it in GitHub Desktop.

Revisions

  1. pwm created this gist Mar 16, 2024.
    32 changes: 32 additions & 0 deletions measure.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,32 @@
    #!/usr/bin/env bash
    set -euo pipefail
    cd "$(git rev-parse --show-toplevel)"

    if [[ "$(uname)" == "Linux" ]]; then
    my_cores=$(nproc)
    elif [[ "$(uname)" == "Darwin" ]]; then
    my_cores=$(sysctl -n hw.ncpu)
    else
    echo "Unknown number of cores ¯\_(ツ)_/¯"
    exit 1
    fi

    out="plot.csv"
    if [[ ! -f "$out" ]]; then
    echo "cores,area,chunk,start,stop" >"$out"
    fi

    for cores in 4 8 12 16 24 32 48 64; do
    if [ "$cores" -le "$my_cores" ]; then
    for area in 32 64 128 256 512; do
    for chunk in 2 4 8; do
    cabal clean
    ghc_flags="--ghc-options=-j$cores +RTS -A${area}m -n${chunk}m -RTS"
    start=$(date --iso=sec)
    cabal build --disable-tests -j "$ghc_flags" language
    stop=$(date --iso=sec)
    echo "$cores,$area,$chunk,$start,$stop" >>"$out"
    done
    done
    fi
    done
    39 changes: 39 additions & 0 deletions plot.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,39 @@
    import sys
    import pandas as pd
    import matplotlib.pyplot as plt

    # Excuse my terrible python skills

    if len(sys.argv) < 2:
    print("Usage: python script_name.py filename.csv")
    sys.exit(1)

    filename = sys.argv[1]
    basename = filename.rsplit('.', 1)[0]
    df = pd.read_csv(filename)

    df['duration'] = (pd.to_datetime(df['stop']) - pd.to_datetime(df['start'])).dt.total_seconds()
    areas = df['area'].unique()
    areas.sort()
    cores = df['cores'].unique()
    cores.sort()

    fig, axs = plt.subplots(len(areas), 1, figsize=(10, 6 * len(areas)), sharex=True, sharey=True)
    if len(areas) == 1: axs = [axs]
    for ax, area in zip(axs, areas):
    df_area = df[df['area'] == area]
    chunks = df_area['chunk'].unique()
    chunks.sort()
    for chunk in chunks:
    df_chunk = df_area[df_area['chunk'] == chunk]
    mean_durations = df_chunk.groupby('cores')['duration'].mean().reset_index().sort_values(by='cores')
    ax.plot(mean_durations['cores'], mean_durations['duration'], marker='o', linestyle='-', label=f'-n{chunk}m')
    ax.set_title(f'-A{area}m')
    ax.legend()
    ax.grid(True)
    ax.set_xticks(cores)
    ax.set_yticks(range(int(df['duration'].min()), int(df['duration'].max()) + 1, 1))
    fig.supxlabel('Cores')
    fig.supylabel('Duration (seconds)')
    plt.tight_layout()
    plt.savefig(f'{basename}.png')