Skip to content

Commit ac084e2

Browse files
committed
python-benchmark
1 parent 50ac00e commit ac084e2

File tree

8 files changed

+1390
-0
lines changed

8 files changed

+1390
-0
lines changed
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
[build-system]
2+
requires = ["poetry-core<2.0.0"]
3+
build-backend = "poetry.core.masonry.api"
4+
5+
[tool.poetry]
6+
name = "esdk-benchmark-python"
7+
version = "0.1.0"
8+
description = "Performance tests DB-ESDK Python"
9+
authors = ["AWS Crypto Tools <[email protected]>"]
10+
readme = "README.md"
11+
packages = [{include = "esdk_benchmark", from = "src"}]
12+
13+
[tool.poetry.dependencies]
14+
python = "^3.11.0"
15+
aws-dbesdk-dynamodb = { path = "../../../DynamoDbEncryption/runtimes/python", develop = false, extras = ["legacy-ddbec"]}
16+
boto3 = ">=1.26.0"
17+
PyYAML = "^6.0"
18+
pydantic = "^2.0.0"
19+
tqdm = "^4.66.0"
20+
psutil = "^5.9.0"
21+
numpy = "^1.24.0"
22+
23+
[tool.poetry.group.dev.dependencies]
24+
pytest = "^7.4.0"
25+
pytest-cov = "^4.1.0"
26+
black = "^23.0.0"
27+
flake8 = "^6.0.0"
28+
mypy = "^1.5.0"
29+
memory-profiler = "^0.60.0"
30+
tox = "^4.0.0"
31+
32+
[tool.poetry.scripts]
33+
esdk-benchmark = "esdk_benchmark.program:main"
34+
35+
[tool.black]
36+
line-length = 88
37+
target-version = ['py311']
38+
include = '\.pyi?$'
39+
exclude = '''
40+
/(
41+
\.eggs
42+
| \.git
43+
| \.hg
44+
| \.mypy_cache
45+
| \.tox
46+
| \.venv
47+
| _build
48+
| buck-out
49+
| build
50+
| dist
51+
)/
52+
'''
53+
54+
[tool.mypy]
55+
python_version = "3.11"
56+
warn_return_any = true
57+
warn_unused_configs = true
58+
disallow_untyped_defs = true
59+
disallow_incomplete_defs = true
60+
check_untyped_defs = true
61+
disallow_untyped_decorators = true
62+
no_implicit_optional = true
63+
warn_redundant_casts = true
64+
warn_unused_ignores = true
65+
warn_no_return = true
66+
warn_unreachable = true
67+
strict_equality = true
68+
69+
[[tool.mypy.overrides]]
70+
module = [
71+
"aws_cryptographic_material_providers.*",
72+
"aws_dbesdk_dynamodb.*",
73+
"tqdm",
74+
"psutil",
75+
]
76+
ignore_missing_imports = true
77+
78+
[tool.pytest.ini_options]
79+
minversion = "7.0"
80+
addopts = "-ra -q --strict-markers --strict-config"
81+
testpaths = ["tests"]
82+
pythonpath = ["src"]
83+
markers = [
84+
"slow: marks tests as slow (deselect with '-m \"not slow\"')",
85+
"integration: marks tests as integration tests",
86+
]
87+
88+
[tool.coverage.run]
89+
source = ["src"]
90+
omit = [
91+
"*/tests/*",
92+
"*/test_*",
93+
]
94+
95+
[tool.coverage.report]
96+
exclude_lines = [
97+
"pragma: no cover",
98+
"def __repr__",
99+
"if self.debug:",
100+
"if settings.DEBUG",
101+
"raise AssertionError",
102+
"raise NotImplementedError",
103+
"if 0:",
104+
"if __name__ == .__main__.:",
105+
"class .*\\bProtocol\\):",
106+
"@(abc\\.)?abstractmethod",
107+
]
108+
109+
[tool.flake8]
110+
max-line-length = 88
111+
extend-ignore = ["E203", "W503"]
112+
max-complexity = 10
113+
per-file-ignores = [
114+
"__init__.py:F401",
115+
"tests/*:S101,D103",
116+
]
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
#!/usr/bin/env python3
2+
# Copyright Amazon.com Inc. or its affiliates. All Rights Reserved.
3+
# SPDX-License-Identifier: Apache-2.0
4+
5+
import os
6+
import sys
7+
import subprocess
8+
from pathlib import Path
9+
10+
11+
def main():
12+
script_dir = Path(__file__).parent.absolute()
13+
os.chdir(script_dir)
14+
15+
print("=== DB-ESDK Python Performance Benchmark ===")
16+
print(f"Working directory: {script_dir}")
17+
18+
# Check virtual environment
19+
in_venv = hasattr(sys, 'real_prefix') or (hasattr(sys, 'base_prefix') and sys.base_prefix != sys.prefix)
20+
if not in_venv:
21+
print("WARNING: Not running in a virtual environment.")
22+
print("It's recommended to create and activate a virtual environment:")
23+
print(" python -m venv benchmark-env")
24+
print(" source benchmark-env/bin/activate # (macOS/Linux)")
25+
print(" benchmark-env\\Scripts\\activate # (Windows)")
26+
print()
27+
28+
# Check Poetry availability
29+
try:
30+
subprocess.run(["poetry", "--version"], check=True, capture_output=True)
31+
print("Found Poetry package manager")
32+
except (subprocess.CalledProcessError, FileNotFoundError):
33+
print("Poetry not found. Please install Poetry first:")
34+
print(" curl -sSL https://install.python-poetry.org | python3 -")
35+
print(" # or")
36+
print(" pip install poetry")
37+
return 1
38+
39+
# Check package installation
40+
try:
41+
result = subprocess.run(["poetry", "run", "python", "-c", "import esdk_benchmark; print(esdk_benchmark.__file__)"],
42+
check=True, capture_output=True, text=True, cwd=script_dir)
43+
print(f"Found esdk_benchmark package at: {result.stdout.strip()}")
44+
except subprocess.CalledProcessError:
45+
print("Installing benchmark package with Poetry...")
46+
try:
47+
subprocess.run(["poetry", "install"], check=True, cwd=script_dir) # Install dependencies via Poetry
48+
print("Package installed successfully.")
49+
except subprocess.CalledProcessError as e:
50+
print(f"Failed to install package: {e}")
51+
print("Please install manually with: poetry install")
52+
return 1
53+
54+
args = sys.argv[1:]
55+
56+
if not args:
57+
print("\nRunning benchmark with default settings...")
58+
print("Use --help to see all available options.")
59+
print("Use --quick for a faster test run.")
60+
print()
61+
62+
# Execute benchmark via Poetry
63+
try:
64+
cmd = ["poetry", "run", "esdk-benchmark"] + args
65+
print(f"Running: {' '.join(cmd)}")
66+
result = subprocess.run(cmd, cwd=script_dir)
67+
return result.returncode
68+
except Exception as e:
69+
print(f"Benchmark execution failed: {e}")
70+
import traceback
71+
traceback.print_exc()
72+
return 1
73+
74+
75+
if __name__ == "__main__":
76+
sys.exit(main())
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Copyright Amazon.com Inc. or its affiliates. All Rights Reserved.
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
from .program import main
5+
6+
if __name__ == "__main__":
7+
exit(main())

0 commit comments

Comments
 (0)