Python : Floating-Point Representation Performance Benchmark Suite - #351
Conversation
…enchmarks for numeric data types
…curate execution time
… and enhancing comments
Answer from Github CopilotDB에서 값이 수시로 바뀌고, 매번 필요한 값만 개별적으로 조회해서 즉시 연산한다면 NumPy를 사용하지 않고 Python의 스칼라 타입으로 처리하는 것이 일반적으로 적절합니다. 다만 “항상 Python 일반적인 선택
예를 들어 DB에 다음과 같이 저장되어 있다면: price DECIMAL(12, 2)Python에서 price = row["price"]
taxed_price = price * Decimal("1.1")반면 다음처럼 근삿값 저장이 의도라면: temperature DOUBLEPython temperature = row["temperature"]
adjusted_temperature = temperature * 1.05NumPy가 적합하지 않은 이유값을 하나씩 조회하는 흐름이 다음과 같다고 가정하면: 여기에 NumPy를 넣으면: 이 됩니다. 데이터가 하나뿐이면 NumPy의 벡터화 이점이 없습니다. 오히려 배열 생성과 변환 비용만 추가됩니다. value = float(row["value"])
result = value * 1.05이런 방식이 더 단순하고 적절합니다. 중요한 점: DB 조회 비용이 훨씬 큼이 경우 성능의 주요 비용은 대개 자료형 연산보다 다음 부분입니다.
DB에서 계산하는 방법도 있음단순한 계산이라면 DB에서 바로 처리할 수도 있습니다. SELECT value * 1.05 AS adjusted_value
FROM measurements
WHERE id = ?;이 경우 Python에서는 계산 결과만 받습니다. 다만 복잡한 계산이거나 DB와 애플리케이션 사이에서 계산 책임을 분리해야 한다면 Python에서 처리하는 편이 나을 수 있습니다. 최종 결론현재 조건이라면:
다만:
즉, 추천 기준은 다음과 같습니다. 따라서 사용자의 상황에서는 NumPy를 제외하는 판단은 타당하지만, |
There was a problem hiding this comment.
🟡 Changes recommended
The new runner’s dependency lookup and script path handling are brittle when invoked outside Python/, and the Decimal benchmark timing currently includes avoidable constant-construction overhead that skews results.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
Adds a small benchmark suite under Python/ to compare memory/time characteristics of Python numeric types vs NumPy arrays, plus a helper runner that installs per-script dependencies defined in YAML.
Changes:
- Add
Python/floating.pybenchmark for float/Decimal/NumPy types and list↔NumPy conversion overhead. - Add
Python/run.py+Python/dependencies.yamlto auto-install benchmark dependencies before execution. - Update root and Python READMEs to link and document the new benchmark.
File summaries
| File | Description |
|---|---|
| README.md | Adds an entry linking to the new benchmark section in Python/README.md. |
| Python/run.py | New script runner that reads dependencies.yaml, installs packages, then runs a target script. |
| Python/README.md | Documents the new benchmark and shows sample invocation/output. |
| Python/floating.py | Implements memory/time benchmarks across Python/Decimal/NumPy and conversion overhead measurements. |
| Python/dependencies.yaml | Declares numpy and pympler as dependencies for floating.py. |
Review details
- Files reviewed: 5/5 changed files
- Comments generated: 3
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
kimpro82
left a comment
There was a problem hiding this comment.
Summary
| Aspect | Details |
|---|---|
| Title | Python : Floating-Point Representation Performance Benchmark Suite |
| Author | kimpro82 (PR owner) |
| State | Open (not draft) |
| Files Changed | 5 files |
| Lines Added/Deleted | +283 / -0 |
| Commits | 11 |
| Comments | 1 |
| Review Comments | 3 |
| Mergeable | Yes (clean state) |
| CI Status | No CI checks shown |
Key Changes
Python/floating.py— Main benchmark script measuring memory and execution time for numeric types and list/array conversion overheadPython/run.py— New dependency runner that reads a YAML config, installs packages, and executes target scriptsPython/dependencies.yaml— Registersnumpyandpymplerdependencies for the benchmarkREADME.md&Python/README.md— Updated with links and documentation for the new benchmark
Review Status
A Copilot review flagged 2 issues to address:
- Brittle path handling in the runner when called outside
Python/directory - Constant overhead in Decimal timing — Decimal object construction is included in the benchmark and skews results
Want me to
- Review the specific comments on the PR to see the detailed feedback
- Examine the file changes to understand the benchmark implementation details
- Help address the review issues flagged by Copilot
Floating-Point Type and Python/NumPy Conversion Benchmark (2026.08.27)
Overview
float,decimal.Decimal, NumPyfloat32, and NumPyfloat64.Components
floating.py: Creates the datasets, measures memory and execution time, and prints the comparison report.run.py: A helper script that readsdependencies.yaml, installs configured packages, and runs the selected Python script.dependencies.yaml: Registersnumpyandpympleras dependencies forfloating.py.Measurements
pympler.asizeof.asizeof.1.05. Python lists use list comprehensions, while NumPy arrays use vectorized multiplication.Execution Commands and Results
--- Running 'floating.py' --- === [Benchmark Report] Data Size: 10,000 elements === === [Numeric Type Benchmark] === === [Python/NumPy Conversion Overhead] === Data Type | Memory (Bytes) | Execution Time (s) Operation | Execution Time (s) ---------------------------------------------------------- -------------------------------------------------- Python float | 325,176 | 0.32852 NumPy direct operation | 0.00264 Decimal | 1,125,176 | 3.15240 Python list operation | 0.28159 NumPy float32 | 40,128 | 0.00204 List to NumPy each time | 0.32939 NumPy float64 | 80,128 | 0.00272 NumPy to list each time | 0.16725 List-NumPy round trip | 0.58042Execution times vary by machine and system load. The important observation is that direct NumPy operations are fast, but repeatedly converting between lists and arrays can make the combined operation slower than staying with a Python list. A practical approach is to convert data once, perform multiple operations while it remains a NumPy array, and convert it back only when necessary.