Skip to content

Commit c5ef140

Browse files
committed
Add README files for examples and benchmark_results
- Add examples/README.md with usage instructions for all examples - Add benchmark_results/README.md with benchmark usage guide - Add reactor_owngil_example.erl and reactor_subinterp_example.erl - Remove old benchmark error logs
1 parent 3dc1893 commit c5ef140

6 files changed

Lines changed: 583 additions & 20 deletions

File tree

benchmark_results/README.md

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
# Benchmark Results
2+
3+
This directory stores benchmark results for tracking performance across versions.
4+
5+
## Running Benchmarks
6+
7+
All benchmark scripts are in the `examples/` directory. Compile first with `rebar3 compile`.
8+
9+
### Quick Benchmark
10+
11+
```bash
12+
escript examples/benchmark.erl --quick
13+
```
14+
15+
### Full Benchmark
16+
17+
```bash
18+
escript examples/benchmark.erl --full
19+
```
20+
21+
### Version Comparison Benchmark
22+
23+
```bash
24+
escript examples/benchmark_compare.erl
25+
```
26+
27+
This outputs a summary table useful for comparing performance between versions.
28+
29+
### Concurrency Benchmark
30+
31+
```bash
32+
escript examples/benchmark.erl --concurrent
33+
```
34+
35+
### Channel API Benchmark
36+
37+
```bash
38+
escript examples/bench_channel.erl
39+
```
40+
41+
Compares Channel API throughput at various message sizes.
42+
43+
### Reactor Modes Benchmark
44+
45+
```bash
46+
escript examples/bench_reactor_modes.erl
47+
```
48+
49+
Compares Reactor performance in worker mode vs subinterpreter mode (Python 3.12+).
50+
51+
### Event Loop Benchmark
52+
53+
```bash
54+
rebar3 shell
55+
> run_benchmark:run().
56+
```
57+
58+
Compares Erlang event loop vs standard asyncio event loop performance.
59+
60+
## Saving Results
61+
62+
To save benchmark results for comparison:
63+
64+
```bash
65+
# Run and save to timestamped file
66+
escript examples/benchmark_compare.erl > benchmark_results/$(date +%Y%m%d_%H%M%S).txt
67+
```
68+
69+
## Result Files
70+
71+
Result files are named with timestamps: `YYYYMMDD_HHMMSS.txt`
72+
73+
Example files:
74+
- `reactor_modes_20260309_093558.txt` - Reactor modes comparison results
75+
76+
## Key Metrics
77+
78+
When comparing versions, focus on:
79+
80+
1. **Sync call latency** - Time per `py:call()` operation
81+
2. **Cast throughput** - Non-blocking `py:cast()` operations per second
82+
3. **Concurrent throughput** - Performance under parallel load
83+
4. **Channel throughput** - Messages per second at various sizes
84+
5. **Reactor modes** - Worker vs subinterpreter performance
85+
86+
## System Information
87+
88+
Benchmarks automatically print system info including:
89+
- Erlang/OTP version
90+
- Number of schedulers
91+
- Python version
92+
- Execution mode (free_threaded, subinterp, multi_executor)
93+
- Max concurrent operations

benchmark_results/baseline_20260224_133948.txt.log

Lines changed: 0 additions & 10 deletions
This file was deleted.

benchmark_results/current_20260224_133950.txt.log

Lines changed: 0 additions & 10 deletions
This file was deleted.

examples/README.md

Lines changed: 169 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,169 @@
1+
# Examples
2+
3+
This directory contains runnable examples demonstrating erlang_python features.
4+
5+
## Prerequisites
6+
7+
```bash
8+
rebar3 compile
9+
```
10+
11+
## Basic Examples
12+
13+
### basic_example.erl
14+
Basic Python calls, eval, and async operations.
15+
```bash
16+
escript examples/basic_example.erl
17+
```
18+
19+
### streaming_example.erl
20+
Streaming from Python generators.
21+
```bash
22+
escript examples/streaming_example.erl
23+
```
24+
25+
### shared_state_example.erl
26+
Shared state between Erlang and Python workers.
27+
```bash
28+
escript examples/shared_state_example.erl
29+
```
30+
31+
### logging_example.erl
32+
Python logging forwarded to Erlang logger, plus distributed tracing.
33+
```bash
34+
escript examples/logging_example.erl
35+
```
36+
37+
### erlang_concurrency.erl
38+
Demonstrates parallel execution using BEAM processes from Python.
39+
```bash
40+
escript examples/erlang_concurrency.erl
41+
```
42+
43+
### reentrant_callback.erl / reentrant_demo.erl
44+
Python calling Erlang calling Python (reentrant callbacks).
45+
```bash
46+
escript examples/reentrant_callback.erl
47+
escript examples/reentrant_demo.erl
48+
```
49+
50+
## AI/ML Examples
51+
52+
These require additional Python packages.
53+
54+
### semantic_search.erl
55+
Semantic search with sentence-transformers.
56+
```bash
57+
python3 -m venv /tmp/ai-venv
58+
/tmp/ai-venv/bin/pip install sentence-transformers numpy
59+
escript examples/semantic_search.erl
60+
```
61+
62+
### rag_example.erl
63+
Retrieval-Augmented Generation with Ollama.
64+
```bash
65+
/tmp/ai-venv/bin/pip install sentence-transformers numpy requests
66+
ollama pull llama3.2
67+
escript examples/rag_example.erl
68+
```
69+
70+
### ai_chat.erl
71+
Interactive AI chat.
72+
```bash
73+
escript examples/ai_chat.erl
74+
```
75+
76+
### embedder_example.erl
77+
Text embeddings generation.
78+
```bash
79+
escript examples/embedder_example.erl
80+
```
81+
82+
## Reactor Examples
83+
84+
### reactor_echo.erl
85+
Simple echo server using Reactor API.
86+
```bash
87+
escript examples/reactor_echo.erl
88+
```
89+
90+
### reactor_subinterp_example.erl
91+
Reactor with subinterpreter isolation (Python 3.12+).
92+
```bash
93+
escript examples/reactor_subinterp_example.erl
94+
```
95+
96+
### reactor_owngil_example.erl
97+
Reactor with OWN_GIL subinterpreters (Python 3.12+).
98+
```bash
99+
escript examples/reactor_owngil_example.erl
100+
```
101+
102+
## Benchmarks
103+
104+
### benchmark.erl
105+
General performance benchmark with options.
106+
```bash
107+
escript examples/benchmark.erl --quick # Quick run
108+
escript examples/benchmark.erl --full # Full benchmark
109+
escript examples/benchmark.erl --concurrent # Concurrency focus
110+
```
111+
112+
### benchmark_compare.erl
113+
Version comparison benchmark with summary table.
114+
```bash
115+
escript examples/benchmark_compare.erl
116+
```
117+
118+
### bench_channel.erl
119+
Channel API throughput benchmark.
120+
```bash
121+
escript examples/bench_channel.erl
122+
```
123+
124+
### bench_reactor_modes.erl
125+
Reactor worker vs subinterpreter benchmark.
126+
```bash
127+
escript examples/bench_reactor_modes.erl
128+
```
129+
130+
### bench_event_loop.erl
131+
Event loop performance comparison.
132+
```bash
133+
escript examples/bench_event_loop.erl
134+
```
135+
136+
### bench_reactor_buffer.erl
137+
Reactor buffer performance.
138+
```bash
139+
escript examples/bench_reactor_buffer.erl
140+
```
141+
142+
### bench_resource_pool.erl
143+
Resource pool benchmark.
144+
```bash
145+
escript examples/bench_resource_pool.erl
146+
```
147+
148+
### run_benchmark.erl
149+
Event loop benchmark (run in shell).
150+
```bash
151+
rebar3 shell
152+
> run_benchmark:run().
153+
```
154+
155+
## Elixir
156+
157+
### elixir_example.exs
158+
Elixir integration example.
159+
```bash
160+
elixir --erl "-pa _build/default/lib/erlang_python/ebin" examples/elixir_example.exs
161+
```
162+
163+
## Other
164+
165+
### gen_test.erl
166+
Test generator for development.
167+
```bash
168+
escript examples/gen_test.erl
169+
```

0 commit comments

Comments
 (0)