This fixes issue #1 #2

Open
j wants to merge 123 commits from Branch_Karen into main
4 changed files with 134 additions and 0 deletions
Showing only changes of commit a010090dba - Show all commits
+58
View File
@@ -0,0 +1,58 @@
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.")
+51
View File
@@ -0,0 +1,51 @@
class Vault:
def __init__(self):
self._treasure = "gold"
self._known_good_copy = self.__dict__.copy()
def __getattribute__(self, name):
if name == "treasure":
if self.__dict__ != self._known_good_copy:
print("Attribute deleted!")
return self._treasure
else:
return object.__getattribute__(self, name)
def __setattr__(self, name, value):
if name != "_treasure" and name != "_known_good_copy":
print("Attribute deletion detected!")
self._known_good_copy = self.__dict__.copy()
object.__setattr__(self, name, value)
v = Vault()
Vault.treasure = " haha monkeypatched"
print(v.treasure)
'''
class Vault:
def __init__(self):
self._treasure = "gold"
self._known_good_copy = self.__dict__.copy()
def __get__(self, instance, owner):
if instance is None:
return self
else:
if instance.__dict__ != self._known_good_copy:
print("Attribute deleted!")
return self._treasure
def __set__(self, instance, value):
print("Attribute deletion detected!")
self._known_good_copy = instance.__dict__.copy()
def __delete__(self, instance):
print("Attribute deletion detected!")
self._known_good_copy = instance.__dict__.copy()
def __set_name__(self, owner, name):
self.name = name
v = Vault()
Vault._treasure = " haha monkeypatched"
print(v._treasure)
'''
+17
View File
@@ -0,0 +1,17 @@
import asyncio
# Define a coroutine function
async def greet(name):
print(f"Hello, {name}!")
await asyncio.sleep(1)
print(f"Goodbye, {name}!")
# Call the coroutine function
coroutine_obj = greet("Karen")
# coroutine_obj is a coroutine object, not the actual execution of the coroutine
# Use an event loop to run the coroutine
loop = asyncio.get_event_loop()
loop.run_until_complete(coroutine_obj)
loop.close()
+8
View File
@@ -0,0 +1,8 @@
def think():
x=1
def think2():
nonlocal x
x=2
think2()
return x
print(think())