Last active
March 28, 2022 16:21
-
-
Save Krewn/2936a5b8415ef6476f7ed8779400b321 to your computer and use it in GitHub Desktop.
This makes a histogram of clock tick durations.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import time | |
import matplotlib.pyplot as plt | |
import math | |
class buckets: | |
def __init__(self): | |
self.data = {} | |
def count(self,bucket): | |
try: | |
self.data[bucket]+=1 | |
except KeyError: | |
self.data[bucket]=1 | |
def ids(self): | |
return sorted(self.data.keys()) | |
def counts(self): | |
return [self.data[k] for k in self.ids()] | |
def softAccess(self,k): | |
try: | |
return self.data[k] | |
except: | |
return 0. | |
bs = [] | |
count = 0 | |
while True: | |
b = buckets() | |
start = time.time() | |
mark1 = time.time() | |
while mark1-start < 1: | |
mark2 = time.time() | |
b.count(mark2-mark1) | |
mark1=mark2 | |
bs.append(b) | |
allids = sorted(list(set().union(*list(set([k for k in bs[n].ids()]) for n in range(0,count+1))))) | |
fig = plt.figure() | |
ax = fig.add_axes([0, 0, 1, 1]) | |
countData = [] | |
for dataid in range(0,count+1): | |
countids = bs[dataid].ids() | |
counts = bs[dataid].counts() | |
idx = 0 | |
countData.append([]) | |
for id in allids: | |
if idx == len(countids): | |
countData[dataid].append(0.) | |
else: | |
if id == countids[idx]: | |
countData[dataid].append(counts[idx]) | |
idx+=1 | |
else: | |
countData[dataid].append(0.) | |
if count == 0: | |
bottom = [0. for k in allids] | |
else: | |
bottom = [sum([(math.log(bs[n].softAccess(k),10) if bs[n].softAccess(k)>1 else 0.1) if bs[n].softAccess(k) else 0. for n in range(0,dataid)]) for k in allids] | |
#bottom = [0. for k in allids] | |
ax.bar([str(k) for k in allids],[(math.log(k,10) if k>1 else 0.1) if k else 0. for k in countData[dataid]],label=str(count),bottom=bottom,alpha=1,align='edge', width=1.0) | |
plt.show() | |
count += 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment