forked from SVIG/python-bootcamp
58 lines
1.6 KiB
Python
58 lines
1.6 KiB
Python
import time
|
|
'''import matplotlib.pyplot as plt'''
|
|
|
|
# Durations to measure in seconds
|
|
durations = [0.01, 0.1, 1.0]
|
|
|
|
# Number of repetitions
|
|
num_repetitions = 100
|
|
|
|
# Lists to store jitter for each duration
|
|
jitter_10ms = []
|
|
jitter_100ms = []
|
|
jitter_1s = []
|
|
|
|
# Function to measure jitter
|
|
def measure_jitter(duration):
|
|
start_time = time.perf_counter_ns()
|
|
time.sleep(duration)
|
|
end_time = time.perf_counter_ns()
|
|
return end_time - start_time
|
|
|
|
# Measure jitter for each duration and repeat for num_repetitions times
|
|
for duration in durations:
|
|
for _ in range(num_repetitions):
|
|
jitter = measure_jitter(duration)
|
|
if duration == 0.01:
|
|
jitter_10ms.append(jitter)
|
|
elif duration == 0.1:
|
|
jitter_100ms.append(jitter)
|
|
elif duration == 1.0:
|
|
jitter_1s.append(jitter)
|
|
'''
|
|
# Create histograms for each duration's jitter
|
|
plt.hist(jitter_10ms, bins=10, color='r', alpha=0.5, label='10ms')
|
|
plt.hist(jitter_100ms, bins=10, color='g', alpha=0.5, label='100ms')
|
|
plt.hist(jitter_1s, bins=10, color='b', alpha=0.5, label='1s')
|
|
plt.xlabel('Jitter (ns)')
|
|
plt.ylabel('Frequency')
|
|
plt.title('Jitter of time.sleep() for Different Durations')
|
|
plt.legend()
|
|
plt.show()
|
|
'''
|
|
|
|
import random
|
|
import secrets
|
|
|
|
# Create a dictionary with 1 million integer keys
|
|
dict = {}
|
|
|
|
for i in range(1000000):
|
|
# Generate a random 64-byte value as bytes
|
|
random_value = secrets.token_bytes(64)
|
|
# Convert the bytes value to hexadecimal representation
|
|
hex_value = random_value.hex()
|
|
# Add the key-value pair to the dictionary
|
|
dict[i] = hex_value
|
|
|
|
print("Dictionary created with 1 million integer keys.") |