Skip to content

Commit 7c07dfc

Browse files
committed
Added copyright + documentation
1 parent e9acd6b commit 7c07dfc

File tree

4 files changed

+56
-10
lines changed

4 files changed

+56
-10
lines changed

tests/performance/perftest/tests.py

Lines changed: 56 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,45 @@
1+
# Copyright 2025-present MongoDB, Inc.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
"""Tests for the MongoDB ODM Performance Benchmark Spec.
16+
17+
See https://github.com/mongodb/specifications/blob/master/source/benchmarking/odm-benchmarking.md
18+
19+
20+
To set up the benchmarks locally::
21+
git clone --depth 1 https://github.com/mongodb/specifications.git
22+
pushd specifications/source/benchmarking/odm-data
23+
tar xf flat_models.tgz
24+
tar xf nested_models.tgz
25+
popd
26+
export TEST_PATH="specifications/source/benchmarking/odm-data"
27+
export OUTPUT_FILE="results.json"
28+
29+
Then to run all benchmarks quickly::
30+
cd tests/performance
31+
FASTBENCH=1 python manage.py test
32+
33+
To run individual benchmarks quickly::
34+
cd tests/performance
35+
FASTBENCH=1 python manage.py test perftest.tests.TestLargeNestedDocFilterArray
36+
"""
37+
138
import json
239
import os
340
import time
441
import warnings
42+
from pathlib import Path
543

644
from bson import ObjectId, encode
745
from django.test import (
@@ -20,10 +58,18 @@
2058

2159
OUTPUT_FILE = os.environ.get("OUTPUT_FILE")
2260

23-
NUM_ITERATIONS = 10
24-
MIN_ITERATION_TIME = 30
25-
MAX_ITERATION_TIME = 60
26-
NUM_DOCS = 10000
61+
if os.environ.get("FASTBENCH"):
62+
NUM_ITERATIONS = 1
63+
MIN_ITERATION_TIME = 5
64+
MAX_ITERATION_TIME = 10
65+
NUM_DOCS = 1000
66+
else:
67+
NUM_ITERATIONS = 10
68+
MIN_ITERATION_TIME = 30
69+
MAX_ITERATION_TIME = 60
70+
NUM_DOCS = 10000
71+
72+
TEST_PATH = os.environ.get("TEST_PATH", Path(os.path.realpath(__file__)).parent.parent / "odm-data")
2773

2874
result_data: list = []
2975

@@ -135,7 +181,7 @@ class SmallFlatDocTest(PerformanceTest):
135181

136182
def setUp(self):
137183
super().setUp()
138-
with open(self.dataset) as data: # noqa: PTH123
184+
with open(Path(TEST_PATH) / Path("flat_models") / self.dataset) as data: # noqa: PTH123
139185
self.document = json.load(data)
140186

141187
self.data_size = len(encode(self.document)) * NUM_DOCS
@@ -215,7 +261,7 @@ class LargeFlatDocTest(PerformanceTest):
215261

216262
def setUp(self):
217263
super().setUp()
218-
with open(self.dataset) as data: # noqa: PTH123
264+
with open(Path(TEST_PATH) / Path("flat_models") / self.dataset) as data: # noqa: PTH123
219265
self.document = json.load(data)
220266

221267
self.data_size = len(encode(self.document)) * NUM_DOCS
@@ -255,7 +301,7 @@ class LargeNestedDocTest(PerformanceTest):
255301

256302
def setUp(self):
257303
super().setUp()
258-
with open(self.dataset) as data: # noqa: PTH123
304+
with open(Path(TEST_PATH) / Path("nested_models") / self.dataset) as data: # noqa: PTH123
259305
self.document = json.load(data)
260306

261307
self.data_size = len(encode(self.document)) * NUM_DOCS
@@ -298,14 +344,14 @@ def setUp(self):
298344
self.models = list(LargeNestedModel.objects.all())
299345
self.data_size = len(encode({"field1": "updated_value"})) * NUM_DOCS
300346

301-
def after(self):
302-
LargeNestedModel.objects.all().delete()
303-
304347
def do_task(self):
305348
for model in self.models:
306349
model.embedded_str_doc_1.field1 = "updated_value"
307350
model.save()
308351

352+
def after(self):
353+
LargeNestedModel.objects.all().delete()
354+
309355

310356
class TestLargeNestedDocFilterById(LargeNestedDocTest, TestCase):
311357
def setUp(self):

0 commit comments

Comments
 (0)