Created
October 27, 2024 14:47
-
-
Save azat/8a0a94e4de2d95af8f729b709589ce12 to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env python3 | |
import matplotlib.pyplot as plt | |
def hashsocket_1(fd): | |
return fd | |
def hashsocket_2(fd): | |
h = fd & 0xffffffff | |
h += (h >> 2) & 0xffffffff | (h << 30) & 0xffffffff | |
return h | |
def hashsocket_3(fd): | |
h = fd & 0xffffffff | |
h = (h >> 2) & 0xffffffff | (h << 30) & 0xffffffff | |
return h | |
n1_values = [] | |
n2_values = [] | |
n3_values = [] | |
prime = 49157 | |
for s in range(0, int(prime*1.2), 4): | |
h1 = hashsocket_1(s) | |
h2 = hashsocket_2(s) | |
h3 = hashsocket_3(s) | |
n1 = h1 % prime | |
n2 = h2 % prime | |
n3 = h3 % prime | |
n1_values.append(n1) | |
n2_values.append(n2) | |
n3_values.append(n3) | |
# Set up subplots for a clear comparison | |
fig, axes = plt.subplots(3, 1, figsize=(10, 12)) | |
# Plot n1 distribution | |
axes[0].hist(n1_values, bins=100, color="skyblue", edgecolor="black") | |
axes[0].set_title("fd % prime") | |
axes[0].set_xlabel("Value") | |
axes[0].set_ylabel("Frequency") | |
# Plot n2 distribution | |
axes[1].hist(n2_values, bins=100, color="salmon", edgecolor="black") | |
axes[1].set_title("hashsocket orig % prime") | |
axes[1].set_xlabel("Value") | |
axes[1].set_ylabel("Frequency") | |
# Plot n3 distribution | |
axes[2].hist(n3_values, bins=100, color="lightgreen", edgecolor="black") | |
axes[2].set_title("hashsocket patched % prime") | |
axes[2].set_xlabel("Value") | |
axes[2].set_ylabel("Frequency") | |
# Adjust layout and show plot | |
plt.tight_layout() | |
plt.show() |
Author
azat
commented
Oct 27, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment