Skip to content

Commit cbdde65

Browse files
committed
SL-18330: Merge branch 'main' into sl-18330-fix
2 parents 05b69f1 + 8fdaf68 commit cbdde65

File tree

5 files changed

+167
-1
lines changed

5 files changed

+167
-1
lines changed

.github/workflows/bench.yaml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
name: Benchmark
2+
3+
on:
4+
pull_request:
5+
6+
permissions:
7+
contents: write
8+
deployments: write
9+
10+
jobs:
11+
benchmark:
12+
name: Run benchmarks
13+
runs-on: ubuntu-latest
14+
steps:
15+
- uses: actions/checkout@v3
16+
17+
- uses: actions/setup-python@v4
18+
with:
19+
python-version: "3.10"
20+
21+
- name: Run benchmarks
22+
run: |
23+
pip install .[dev]
24+
pytest tests/bench.py --benchmark-json benchmark.json
25+
26+
- name: Store results
27+
uses: benchmark-action/github-action-benchmark@v1
28+
with:
29+
name: Python Benchmarks
30+
tool: pytest
31+
output-file-path: benchmark.json
32+
github-token: ${{ secrets.GITHUB_TOKEN }}
33+
auto-push: true
34+
alert-threshold: "110%"
35+
comment-on-alert: true

.github/workflows/ci.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,9 @@ jobs:
4343

4444
- name: Upload coverage
4545
uses: codecov/codecov-action@v3
46+
if: matrix.python-version == '3.10'
4647
with:
48+
token: ${{ secrets.CODECOV_TOKEN }}
4749
env_vars: PYTHON
4850
fail_ci_if_error: true
4951
files: .coverage.${{ steps.pyenv.outputs.value }}.xml

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,3 +283,5 @@ $RECYCLE.BIN/
283283
*.lnk
284284

285285
# End of https://www.toptal.com/developers/gitignore/api/python,linux,windows,macos,vim,visualstudiocode
286+
287+
.benchmarks/

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
'local_scheme': 'no-local-version', # disable local-version to allow uploads to test.pypi.org
2323
},
2424
extras_require={
25-
"dev": ["pytest", "pytest-cov<3"],
25+
"dev": ["pytest", "pytest-benchmark", "pytest-cov<3"],
2626
},
2727
classifiers=[
2828
"Intended Audience :: Developers",

tests/bench.py

Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
from tempfile import TemporaryFile
2+
import unittest
3+
4+
import pytest
5+
6+
import llsd
7+
8+
BENCH_DATA_XML = b"""<?xml version="1.0" encoding="UTF-8"?>
9+
<llsd>
10+
<map>
11+
<key>integer</key>
12+
<real>5000</real>
13+
<key>real</key>
14+
<real>0.096970</real>
15+
<key>binary</key>
16+
<binary>ff55ca5cef2f477f92e011c7de95bb11</binary>
17+
<key>uri</key>
18+
<uri>https://secondlife.com</uri>
19+
<key>date</key>
20+
<date>2006-02-01T14:29:53Z</date>
21+
<key>children</key>
22+
<array>
23+
<map>
24+
<key>integer</key>
25+
<real>5000</real>
26+
<key>real</key>
27+
<real>0.096970</real>
28+
<key>binary</key>
29+
<binary>ff55ca5cef2f477f92e011c7de95bb11</binary>
30+
<key>string</key>
31+
<string>AjWwhTHctcuAxhxK</string>
32+
<key>id</key>
33+
<binary>ff55ca5cef2f477f92e011c7de95bb11</binary>
34+
<key>int_32</key>
35+
<integer>-1147906088</integer>
36+
<key>bool</key>
37+
<boolean>1</boolean>
38+
</map>
39+
<real>0.156519</real>
40+
<binary>ff55ca5cef2f477f92e011c7de95bb11</binary>
41+
<uri>https://secondlife.com</uri>
42+
<date>2006-02-01T14:29:53Z</date>
43+
</array>
44+
</map>
45+
</llsd>"""
46+
47+
_bench_data = llsd.parse_xml(BENCH_DATA_XML)
48+
BENCH_DATA_BINARY = llsd.format_binary(_bench_data)
49+
BENCH_DATA_NOTATION = llsd.format_notation(_bench_data)
50+
51+
_tc = unittest.TestCase()
52+
_tc.maxDiff = 5000
53+
assertDictEqual = _tc.assertDictEqual
54+
55+
56+
@pytest.fixture
57+
def xml_stream():
58+
with TemporaryFile() as f:
59+
f.write(BENCH_DATA_XML)
60+
f.seek(0)
61+
yield f
62+
63+
64+
@pytest.fixture
65+
def notation_stream():
66+
with TemporaryFile() as f:
67+
d = llsd.format_notation(_bench_data)
68+
f.write(d)
69+
f.seek(0)
70+
yield f
71+
72+
73+
@pytest.fixture
74+
def binary_stream():
75+
with TemporaryFile() as f:
76+
d = llsd.format_binary(_bench_data)
77+
f.write(d)
78+
f.seek(0)
79+
yield f
80+
81+
82+
def bench_stream(parse, stream):
83+
ret = parse(stream)
84+
stream.seek(0)
85+
return ret
86+
87+
88+
def test_parse_xml_stream(benchmark, xml_stream):
89+
ret = benchmark(bench_stream, llsd.parse_xml, xml_stream)
90+
assertDictEqual(ret, _bench_data)
91+
92+
93+
def test_parse_notation_stream(benchmark, notation_stream):
94+
ret = benchmark(bench_stream, llsd.parse_notation, notation_stream)
95+
assertDictEqual(ret, _bench_data)
96+
97+
98+
def test_parse_binary_stream(benchmark, binary_stream):
99+
ret = benchmark(bench_stream, llsd.parse_binary, binary_stream)
100+
assertDictEqual(ret, _bench_data)
101+
102+
103+
def test_parse_notation_bytes(benchmark):
104+
ret = benchmark(llsd.parse_notation, BENCH_DATA_NOTATION)
105+
assertDictEqual(ret, _bench_data)
106+
107+
108+
def test_parse_xml_bytes(benchmark):
109+
res = benchmark(llsd.parse_xml, BENCH_DATA_XML)
110+
assertDictEqual(res, _bench_data)
111+
112+
113+
def test_parse_binary_bytes(benchmark):
114+
res = benchmark(llsd.parse_binary, BENCH_DATA_BINARY)
115+
assertDictEqual(res, _bench_data)
116+
117+
118+
def test_format_xml(benchmark):
119+
benchmark(llsd.format_xml, _bench_data)
120+
121+
122+
def test_format_notation(benchmark):
123+
benchmark(llsd.format_notation, _bench_data)
124+
125+
126+
def test_format_binary(benchmark):
127+
benchmark(llsd.format_binary, _bench_data)

0 commit comments

Comments
 (0)