Skip to content

Instantly share code, notes, and snippets.

@itamarhaber
Last active August 29, 2015 14:20
Show Gist options
  • Save itamarhaber/2dad94e3bdd2980bce73 to your computer and use it in GitHub Desktop.
Save itamarhaber/2dad94e3bdd2980bce73 to your computer and use it in GitHub Desktop.
Haber's Benchmarking Theorem (as postulated for Ask a Redis Expert™ Webinar: How to Achieve 1.5M ops/sec with Redis, https://www.youtube.com/watch?v=yS-Z9JnkWsA)
"""
Haber's Benchamarketing Theorem
"""
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.font_manager as fm
with plt.xkcd():
fig = plt.figure()
font = fm.FontProperties(fname='./xkcd-Regular.otf')
x = np.linspace(0, 1)
yu = x / x
yf = 1 - x
yr = np.power(yf, 42)
ax = fig.add_axes((0.1, 0.32, 0.8, 0.55))
lu = ax.plot(x, yu, 'g', label='utopian')
lf = ax.plot(x, yf, 'm', label='fair world')
lr = ax.plot(x, yr, 'r', label='real life')
plt.legend(loc=(0.72, 0.5), prop=font)
plt.ylim(-0.02, 1.02)
ax.spines['right'].set_color('none')
ax.spines['top'].set_color('none')
ax.xaxis.set_ticks_position('none')
ax.yaxis.set_ticks_position('none')
ax.set_xticklabels([])
ax.set_yticklabels([])
ttl = plt.title('Benchmarking Theorem', fontproperties=font, fontsize=28)
ttl.set_y(1.05)
plt.ylabel('probability of accuracy', fontproperties=font)
fig.text(0.05, 0.28, 'your app', fontproperties=font, size=14)
fig.text(0.42, 0.28, 'other apps', fontproperties=font, size=14)
fig.text(0.78, 0.28, 'hello_world.c', fontproperties=font, size=14)
fig.text(0.03, 0.85, '100%', fontproperties=font, size=14)
fig.text(0.05, 0.32, '0%', fontproperties=font, size=14)
fig.text(0.03, 0.18, 'The probability that results from a benchmark accurately', fontproperties=font, size=18)
fig.text(0.03, 0.13, 'reflect your app is infinitesimal, unless done on it', fontproperties=font, size=18)
fig.text(0.66, 0.04, '@itamarhaber /cc @xkcd', fontproperties=font, size=14)
# Tweak spacing to prevent clipping of ylabel
plt.subplots_adjust(left=0.15)
plt.show()
"""
Butterfly curve - http://en.wikipedia.org/wiki/Butterfly_curve_%28transcendental%29
"""
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.font_manager as fm
with plt.xkcd():
fig = plt.figure()
font = fm.FontProperties(fname='./xkcd-Regular.otf')
t = np.linspace(-5, 5, 420)
x = np.sin(t) * (np.exp(np.cos(t)) - 2 * np.cos(4 * t) - np.power(np.sin(t/12), 5))
y = np.cos(t) * (np.exp(np.cos(t)) - 2 * np.cos(4 * t) - np.power(np.sin(t/12), 5))
lc = plt.plot(x, y, 'k', label='chaos')
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment