plot.py 1.96 KB
Newer Older
1 2
import numpy as np
from matplotlib import pyplot as plt
3
from matplotlib.patches import Patch
4 5 6 7

labels = ['loop overhead',
          'function call',
          'stack switching',
8 9 10 11
          'setjmp and stack switching',
          'minimal fcontext overhead',
          'minimum callcc overhead',
          'custom assembly'
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
          ]

call_color = (0.3, 0.1, 0.4, 0.6)
setjmp_color = (0.3, 0.3, 0.4, 0.6)
fcontext_color = (0.3, 0.6, 0.4, 0.6)
custom_color = (0.3, 1.0, 0.4, 0.6)
colors = [
    call_color,
    call_color,
    setjmp_color,
    setjmp_color,
    fcontext_color,
    fcontext_color,
    custom_color
]

dataX86 = np.array([
    0.55,
    2.79,
    5.60,
    14.93,
    11.00,
    18.66,
    7.86,
])
37
dataARM32 = np.array([
38 39 40 41 42 43 44 45 46 47
    1.26,
    4.97,
    11.25,
    54.50,
    57.45,
    101.29,
    23.74,
])


48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
def plot_data(data, name):
    plt.clf()

    # Make sure pgf plots have correct fonts
    pgf_with_rc_fonts = {
        "font.family": "serif",
        "font.serif": [""],
        "font.sans-serif": [""],
    }
    plt.rcParams.update(pgf_with_rc_fonts)

    xAxis = np.array(range(0, len(labels)))

    plt.bar(xAxis, data, color=colors)
    plt.xticks(xAxis, labels, rotation=90)
    plt.ylabel('runtime in ns')
    plt.subplots_adjust(bottom=0.5, top=0.98)

    custom_lines = [Patch(facecolor=call_color, edgecolor='k'),
                    Patch(facecolor=setjmp_color, edgecolor='k'),
                    Patch(facecolor=fcontext_color, edgecolor='k'),
                    Patch(facecolor=custom_color, edgecolor='k')]
    custom_labels = ['baseline',
                     'setjmp',
                     'fcontext',
                     'custom']
    plt.legend(custom_lines, custom_labels)

    fig = plt.gcf()
    fig.set_size_inches(5, 5)
    fig.set_dpi(300)
    # bounds = Bbox.from_bounds(-0.1, -0.1, 4.75, 4.6)

    fig.savefig(name + '.pgf')
    fig.savefig(name + '.png')

84

85 86
plot_data(dataX86, "plots/context_switch_x86_64")
plot_data(dataARM32, "plots/context_switch_arm32")