import time from fractions import Fraction as F import matplotlib.pyplot as plt NOW_NS = int(time.time()) * 10 ** 9 THEN_NS = NOW_NS + 5000 plt.title("Comparing conversions over 5 us") xs = range(NOW_NS, THEN_NS + 1) y1 = [round(F(x / 10**9) * 10**9) - x for x in xs] y2 = [int(x / 1e9 * 1e9) - x for x in xs] y3 = [abs(a) - abs(b) for a, b in zip(y1, y2)] plt.plot( y1, drawstyle='steps-mid', color="red", label="Errors with 'round(F(x / 10**9) * 10**9)'") plt.plot( y2, drawstyle='steps-mid', color="blue", label="Errors with 'int(x / 1e9 * 1e9)'") plt.plot( y3, drawstyle='steps-mid', color="green", label="Comparing absolute errors") plt.legend() plt.show()