Skip to content

Commit 7fe7f1c

Browse files
committed
Refactor test result parsing; minor C# test cleanups
Refactor Python test result parsing into charts_utils.py for reuse across chart scripts, removing duplication. Update C# tests for clarity in array size calculations and modernize ReadAsync usage. Remove obsolete XML doc in IRepository, optimize assembly check in ServiceCollectionExtensions, and clean up whitespace in StreamRequestHandlerWrapper.
1 parent f15b594 commit 7fe7f1c

8 files changed

Lines changed: 52 additions & 122 deletions

File tree

Sources/EasyExtensions.Crypto.Tests.Charts/advanced_analysis.py

Lines changed: 1 addition & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -3,46 +3,9 @@
33
import pandas as pd
44
import numpy as np
55
import seaborn as sns
6+
from charts_utils import parse_test_results
67

78

8-
def parse_test_results(filename):
9-
"""Parse performance test results from a file"""
10-
11-
with open(filename, 'r', encoding='utf-8') as f:
12-
content = f.read()
13-
14-
# Find result sections
15-
encrypt_section = re.search(
16-
r'=== ENCRYPTION THREAD/CHUNK SWEEP ===(.*?)(?===|$)', content, re.DOTALL)
17-
decrypt_section = re.search(
18-
r'=== DECRYPTION THREAD/CHUNK SWEEP ===(.*?)(?===|$)', content, re.DOTALL)
19-
20-
def extract_data(section_text):
21-
"""Extract data from a text section"""
22-
if not section_text:
23-
return pd.DataFrame()
24-
25-
# Ищем строки с данными (формат: число | число | число.число)
26-
pattern = r'(\d+)\s*\|\s*(\d+)\s*\|\s*([\d.]+)'
27-
matches = re.findall(pattern, section_text)
28-
29-
data = []
30-
for match in matches:
31-
threads = int(match[0])
32-
chunk_mb = int(match[1])
33-
throughput = float(match[2])
34-
data.append({'Threads': threads, 'ChunkMB': chunk_mb,
35-
'Throughput': throughput})
36-
37-
return pd.DataFrame(data)
38-
39-
encrypt_data = extract_data(
40-
encrypt_section.group(1) if encrypt_section else "")
41-
decrypt_data = extract_data(
42-
decrypt_section.group(1) if decrypt_section else "")
43-
44-
return encrypt_data, decrypt_data
45-
469

4710
def create_advanced_plots(encrypt_data, decrypt_data):
4811
"""Create an advanced set of plots with additional analysis"""
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import re
2+
import pandas as pd
3+
4+
5+
def parse_test_results(filename):
6+
"""Parse performance test results from a file.
7+
8+
Returns a tuple (encrypt_data, decrypt_data) as pandas DataFrames.
9+
"""
10+
11+
with open(filename, 'r', encoding='utf-8') as f:
12+
content = f.read()
13+
14+
# Find result sections
15+
encrypt_section = re.search(
16+
r'=== ENCRYPTION THREAD/CHUNK SWEEP ===(.*?)(?===|$)', content, re.DOTALL)
17+
decrypt_section = re.search(
18+
r'=== DECRYPTION THREAD/CHUNK SWEEP ===(.*?)(?===|$)', content, re.DOTALL)
19+
20+
def extract_data(section_text):
21+
"""Extract data from a text section"""
22+
if not section_text:
23+
return pd.DataFrame()
24+
25+
pattern = r'(\d+)\s*\|\s*(\d+)\s*\|\s*([\d.]+)'
26+
matches = re.findall(pattern, section_text)
27+
28+
data = []
29+
for match in matches:
30+
threads = int(match[0])
31+
chunk_mb = int(match[1])
32+
throughput = float(match[2])
33+
data.append({'Threads': threads, 'ChunkMB': chunk_mb,
34+
'Throughput': throughput})
35+
36+
return pd.DataFrame(data)
37+
38+
encrypt_data = extract_data(
39+
encrypt_section.group(1) if encrypt_section else "")
40+
decrypt_data = extract_data(
41+
decrypt_section.group(1) if decrypt_section else "")
42+
43+
return encrypt_data, decrypt_data

Sources/EasyExtensions.Crypto.Tests.Charts/mega_advanced_analysis.py

Lines changed: 1 addition & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -5,46 +5,9 @@
55
import seaborn as sns
66
from matplotlib.patches import Rectangle
77
import matplotlib.gridspec as gridspec
8+
from charts_utils import parse_test_results
89

910

10-
def parse_test_results(filename):
11-
"""Parse performance test results from a file"""
12-
13-
with open(filename, 'r', encoding='utf-8') as f:
14-
content = f.read()
15-
16-
# Find result sections
17-
encrypt_section = re.search(
18-
r'=== ENCRYPTION THREAD/CHUNK SWEEP ===(.*?)(?===|$)', content, re.DOTALL)
19-
decrypt_section = re.search(
20-
r'=== DECRYPTION THREAD/CHUNK SWEEP ===(.*?)(?===|$)', content, re.DOTALL)
21-
22-
def extract_data(section_text):
23-
"""Extract data from a text section"""
24-
if not section_text:
25-
return pd.DataFrame()
26-
27-
# Ищем строки с данными (формат: число | число | число.число)
28-
pattern = r'(\d+)\s*\|\s*(\d+)\s*\|\s*([\d.]+)'
29-
matches = re.findall(pattern, section_text)
30-
31-
data = []
32-
for match in matches:
33-
threads = int(match[0])
34-
chunk_mb = int(match[1])
35-
throughput = float(match[2])
36-
data.append({'Threads': threads, 'ChunkMB': chunk_mb,
37-
'Throughput': throughput})
38-
39-
return pd.DataFrame(data)
40-
41-
encrypt_data = extract_data(
42-
encrypt_section.group(1) if encrypt_section else "")
43-
decrypt_data = extract_data(
44-
decrypt_section.group(1) if decrypt_section else "")
45-
46-
return encrypt_data, decrypt_data
47-
4811

4912
def create_mega_analysis(encrypt_data, decrypt_data):
5013
"""Create an extended set of 12 plots with detailed analysis"""

Sources/EasyExtensions.Crypto.Tests.Charts/simple_charts.py

Lines changed: 1 addition & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -2,46 +2,9 @@
22
import matplotlib.pyplot as plt
33
import pandas as pd
44
import numpy as np
5+
from charts_utils import parse_test_results
56

67

7-
def parse_test_results(filename):
8-
"""Parse performance test results from a file"""
9-
10-
with open(filename, 'r', encoding='utf-8') as f:
11-
content = f.read()
12-
13-
# Find result sections
14-
encrypt_section = re.search(
15-
r'=== ENCRYPTION THREAD/CHUNK SWEEP ===(.*?)(?===|$)', content, re.DOTALL)
16-
decrypt_section = re.search(
17-
r'=== DECRYPTION THREAD/CHUNK SWEEP ===(.*?)(?===|$)', content, re.DOTALL)
18-
19-
def extract_data(section_text):
20-
"""Extract data from a text section"""
21-
if not section_text:
22-
return pd.DataFrame()
23-
24-
# Find data lines (format: number | number | number.number)
25-
pattern = r'(\d+)\s*\|\s*(\d+)\s*\|\s*([\d.]+)'
26-
matches = re.findall(pattern, section_text)
27-
28-
data = []
29-
for match in matches:
30-
threads = int(match[0])
31-
chunk_mb = int(match[1])
32-
throughput = float(match[2])
33-
data.append({'Threads': threads, 'ChunkMB': chunk_mb,
34-
'Throughput': throughput})
35-
36-
return pd.DataFrame(data)
37-
38-
encrypt_data = extract_data(
39-
encrypt_section.group(1) if encrypt_section else "")
40-
decrypt_data = extract_data(
41-
decrypt_section.group(1) if decrypt_section else "")
42-
43-
return encrypt_data, decrypt_data
44-
458

469
def create_plots(encrypt_data, decrypt_data):
4710
"""Create four polished plots"""

Sources/EasyExtensions.Crypto.Tests/AesGcmStreamCipherPipeTests.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public async Task EncryptAsync_StreamOverload_DecryptsCorrectly()
1616
{
1717
var key = Key();
1818
var cipher = new AesGcmStreamCipher(key, keyId: 11, threads: 2);
19-
byte[] data = [.. Enumerable.Range(0, 3 * AesGcmStreamCipher.MinChunkSize + 123).Select(i => (byte)(i & 0xFF))];
19+
byte[] data = [.. Enumerable.Range(0, (3 * AesGcmStreamCipher.MinChunkSize) + 123).Select(i => (byte)(i & 0xFF))];
2020

2121
using var input1 = new MemoryStream(data);
2222
using var directOut = new MemoryStream();
@@ -45,7 +45,7 @@ public async Task RoundTrip_EncryptDecrypt_StreamOverloads()
4545
{
4646
var key = Key();
4747
var cipher = new AesGcmStreamCipher(key, keyId: 12, threads: 2);
48-
byte[] data = [.. Enumerable.Range(0, 5 * AesGcmStreamCipher.MinChunkSize + 777).Select(i => (byte)(i & 0xFF))];
48+
byte[] data = [.. Enumerable.Range(0, (5 * AesGcmStreamCipher.MinChunkSize) + 777).Select(i => (byte)(i & 0xFF))];
4949

5050
using var input = new MemoryStream(data);
5151
var encStream = await cipher.EncryptAsync(input, chunkSize: AesGcmStreamCipher.MinChunkSize);
@@ -79,7 +79,7 @@ public async Task EncryptAsync_StreamOverload_Cancellation()
7979
{
8080
while (true)
8181
{
82-
int r = await stream.ReadAsync(buffer, 0, buffer.Length, cts.Token);
82+
int r = await stream.ReadAsync(buffer, cts.Token);
8383
if (r == 0) break;
8484
totalRead += r;
8585
await Task.Delay(5); // slow down to increase chance of cancellation
@@ -115,7 +115,7 @@ public async Task DecryptAsync_StreamOverload_Cancellation()
115115
{
116116
while (true)
117117
{
118-
int r = await decStream.ReadAsync(buffer, 0, buffer.Length, cts.Token);
118+
int r = await decStream.ReadAsync(buffer, cts.Token);
119119
if (r == 0) break;
120120
totalRead += r;
121121
await Task.Delay(5); // slow down to increase chance of cancellation
@@ -155,7 +155,7 @@ public async Task DecryptAsync_StreamOverload_Tamper_Throws()
155155
{
156156
var key = Key();
157157
var cipher = new AesGcmStreamCipher(key, keyId: 16);
158-
byte[] data = [.. Enumerable.Range(0, 3 * AesGcmStreamCipher.MinChunkSize + 10).Select(i => (byte)(i & 0xFF))];
158+
byte[] data = [.. Enumerable.Range(0, (3 * AesGcmStreamCipher.MinChunkSize) + 10).Select(i => (byte)(i & 0xFF))];
159159
using var input = new MemoryStream(data);
160160
var encStream = await cipher.EncryptAsync(input, chunkSize: AesGcmStreamCipher.MinChunkSize);
161161
using var ciphertextCollected = new MemoryStream();

Sources/EasyExtensions.EntityFrameworkCore/Repository/IRepository.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ public interface IRepository<TItem> : IRepository where TItem : BaseEntity<int>
3030
[Obsolete("Use AddAsync() instead.")]
3131
Task<TItem> CreateAsync(TItem item, CancellationToken cancellationToken = default);
3232

33-
3433
/// <summary>
3534
/// Creates a new entity asynchronously.
3635
/// </summary>

Sources/EasyExtensions.Mediator/MicrosoftExtensionsDI/ServiceCollectionExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public static IServiceCollection AddMediator(this IServiceCollection services,
5555
public static IServiceCollection AddMediator(this IServiceCollection services,
5656
MediatorServiceConfiguration configuration)
5757
{
58-
if (!configuration.AssembliesToRegister.Any())
58+
if (configuration.AssembliesToRegister.Count == 0)
5959
{
6060
throw new ArgumentException("No assemblies found to scan. Supply at least one assembly to scan for handlers.");
6161
}

Sources/EasyExtensions.Mediator/Wrappers/StreamRequestHandlerWrapper.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ IAsyncEnumerable<TResponse> Handler() => serviceProvider
5959
}
6060
}
6161

62-
6362
private static async IAsyncEnumerable<T> NextWrapper<T>(
6463
IAsyncEnumerable<T> items,
6564
[EnumeratorCancellation] CancellationToken cancellationToken)

0 commit comments

Comments
 (0)