|
1 | 1 | #!/usr/bin/env python3
|
2 | 2 | import sys
|
3 |
| -from typing import Callable |
4 |
| -from datetime import datetime, timedelta, timezone |
5 | 3 | from contextlib import contextmanager
|
| 4 | +from datetime import datetime, timedelta, timezone |
| 5 | +from typing import Callable |
6 | 6 |
|
7 | 7 | from aw_core.models import Event
|
8 | 8 |
|
9 |
| -from takethetime import ttt |
10 |
| - |
11 |
| -from aw_datastore import get_storage_methods, Datastore |
| 9 | +from aw_datastore import get_storage_methods |
12 | 10 | from aw_datastore.storages import AbstractStorage
|
13 | 11 |
|
14 | 12 | td1s = timedelta(seconds=1)
|
@@ -39,54 +37,58 @@ def temporary_bucket(ds):
|
39 | 37 |
|
40 | 38 |
|
41 | 39 | def benchmark(storage: Callable[..., AbstractStorage]):
|
42 |
| - if storage.__name__ == "PeeweeStorage": |
43 |
| - ds = Datastore(storage, testing=True, filepath="test.db") |
44 |
| - else: |
45 |
| - ds = Datastore(storage, testing=True) |
46 |
| - |
47 |
| - num_single_events = 50 |
48 |
| - num_replace_events = 50 |
49 |
| - num_bulk_events = 20_000 |
50 |
| - num_events = num_single_events + num_replace_events + num_bulk_events + 1 |
51 |
| - num_final_events = num_single_events + num_bulk_events + 1 |
52 |
| - |
53 |
| - events = create_test_events(num_events) |
54 |
| - single_events = events[:num_single_events] |
55 |
| - replace_events = events[num_single_events : num_single_events + num_replace_events] |
56 |
| - bulk_events = events[num_single_events + num_replace_events : -1] |
57 |
| - |
58 |
| - print(storage.__name__) |
59 |
| - |
60 |
| - with temporary_bucket(ds) as bucket: |
61 |
| - with ttt(" sum"): |
62 |
| - with ttt(f" single insert {num_single_events} events"): |
63 |
| - for event in single_events: |
64 |
| - bucket.insert(event) |
65 |
| - |
66 |
| - with ttt(f" bulk insert {num_bulk_events} events"): |
67 |
| - bucket.insert(bulk_events) |
68 |
| - |
69 |
| - with ttt(f" replace last {num_replace_events}"): |
70 |
| - for e in replace_events: |
71 |
| - bucket.replace_last(e) |
72 |
| - |
73 |
| - with ttt(" insert 1 event"): |
74 |
| - bucket.insert(events[-1]) |
75 |
| - |
76 |
| - with ttt(" get one"): |
77 |
| - events_tmp = bucket.get(limit=1) |
78 |
| - |
79 |
| - with ttt(" get all"): |
80 |
| - events_tmp = bucket.get(limit=-1) |
81 |
| - assert len(events_tmp) == num_final_events |
82 |
| - |
83 |
| - with ttt(" get range"): |
84 |
| - events_tmp = bucket.get( |
85 |
| - limit=-1, |
86 |
| - starttime=events[1].timestamp + 0.01 * td1s, |
87 |
| - endtime=events[-1].timestamp + events[-1].duration, |
88 |
| - ) |
89 |
| - assert len(events_tmp) == num_final_events - 1 |
| 40 | + raise NotImplementedError( |
| 41 | + "No longer implemented as ttt/takethetime dependency is removed" |
| 42 | + ) |
| 43 | + |
| 44 | + # if storage.__name__ == "PeeweeStorage": |
| 45 | + # ds = Datastore(storage, testing=True, filepath="test.db") |
| 46 | + # else: |
| 47 | + # ds = Datastore(storage, testing=True) |
| 48 | + |
| 49 | + # num_single_events = 50 |
| 50 | + # num_replace_events = 50 |
| 51 | + # num_bulk_events = 20_000 |
| 52 | + # num_events = num_single_events + num_replace_events + num_bulk_events + 1 |
| 53 | + # num_final_events = num_single_events + num_bulk_events + 1 |
| 54 | + |
| 55 | + # events = create_test_events(num_events) |
| 56 | + # single_events = events[:num_single_events] |
| 57 | + # replace_events = events[num_single_events : num_single_events + num_replace_events] |
| 58 | + # bulk_events = events[num_single_events + num_replace_events : -1] |
| 59 | + |
| 60 | + # print(storage.__name__) |
| 61 | + |
| 62 | + # with temporary_bucket(ds) as bucket: |
| 63 | + # with ttt(" sum"): |
| 64 | + # with ttt(f" single insert {num_single_events} events"): |
| 65 | + # for event in single_events: |
| 66 | + # bucket.insert(event) |
| 67 | + |
| 68 | + # with ttt(f" bulk insert {num_bulk_events} events"): |
| 69 | + # bucket.insert(bulk_events) |
| 70 | + |
| 71 | + # with ttt(f" replace last {num_replace_events}"): |
| 72 | + # for e in replace_events: |
| 73 | + # bucket.replace_last(e) |
| 74 | + |
| 75 | + # with ttt(" insert 1 event"): |
| 76 | + # bucket.insert(events[-1]) |
| 77 | + |
| 78 | + # with ttt(" get one"): |
| 79 | + # events_tmp = bucket.get(limit=1) |
| 80 | + |
| 81 | + # with ttt(" get all"): |
| 82 | + # events_tmp = bucket.get(limit=-1) |
| 83 | + # assert len(events_tmp) == num_final_events |
| 84 | + |
| 85 | + # with ttt(" get range"): |
| 86 | + # events_tmp = bucket.get( |
| 87 | + # limit=-1, |
| 88 | + # starttime=events[1].timestamp + 0.01 * td1s, |
| 89 | + # endtime=events[-1].timestamp + events[-1].duration, |
| 90 | + # ) |
| 91 | + # assert len(events_tmp) == num_final_events - 1 |
90 | 92 |
|
91 | 93 |
|
92 | 94 | if __name__ == "__main__":
|
|
0 commit comments