Skip to content

Instantly share code, notes, and snippets.

@Cioscos
Last active January 30, 2024 08:25
Show Gist options
  • Save Cioscos/2cc6859f7d12b95a7f142f66584ecf17 to your computer and use it in GitHub Desktop.
Save Cioscos/2cc6859f7d12b95a7f142f66584ecf17 to your computer and use it in GitHub Desktop.
from reedsolo import RSCodec
import numpy as np
import matplotlib.pyplot as plt
# Initialize RSCodec with your number of ecc_bytes
ecc_bytes = 10
rs = RSCodec(ecc_bytes)
def test_rscodec_behavior(data_size_range):
"""
Test the behavior of RSCodec encoding for different sizes of data.
Args:
- data_size_range (tuple): A tuple containing the minimum and maximum data sizes to test.
Returns:
- A list of tuples with (input_size, output_size).
"""
results = []
for data_size in range(*data_size_range):
data = bytes(np.random.randint(0, 256, data_size, dtype=np.uint8))
encoded_data = rs.encode(data)
results.append((data_size, len(encoded_data)))
return results
# Define your data size range (min_size, max_size)
data_size_range = (1, 4096)
# Run the test
results = test_rscodec_behavior(data_size_range, ecc_bytes)
for input_size, output_size in results:
print(f"Input size: {input_size}, Output size: {output_size}, Difference: {output_size - input_size}")
input_sizes, output_sizes = zip(*results)
differences = [output - input for input, output in results]
plt.figure(figsize=(10, 5))
plt.plot(input_sizes, differences, label='Output Size - Input Size')
plt.xlabel('Input Size')
plt.ylabel('Difference')
plt.title('Difference between Output and Input Sizes of RSCodec Encoding')
plt.legend()
plt.grid(True)
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment