-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #26 from nir0s/optimize-perf
Optimize perf
- Loading branch information
Showing
6 changed files
with
158 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
.[cli] | ||
.[color] | ||
numpy | ||
pytest | ||
pytest-cov | ||
mock==2.0.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
from datetime import datetime | ||
|
||
import numpy | ||
import pytest | ||
|
||
import wryte | ||
from wryte import Wryte | ||
|
||
|
||
class TestPerf(object): | ||
def _test_simple_message(self): | ||
w = Wryte(color=False, simple=True) | ||
|
||
timing = [] | ||
|
||
for _ in range(5): | ||
now = datetime.now() | ||
|
||
for _ in range(10): | ||
w.info('My Message') | ||
|
||
timing.append((datetime.now() - now).total_seconds() * 1000.0) | ||
|
||
# This is just a benchmark. This should NEVER take this long. | ||
assert numpy.average(timing[1:]) < 10 | ||
|
||
def test_simple_context(self): | ||
w = Wryte(color=False) | ||
|
||
timing = [] | ||
|
||
for _ in range(5): | ||
now = datetime.now() | ||
|
||
for _ in range(10): | ||
w.info('My Message', {'key': 'value'}) | ||
|
||
timing.append((datetime.now() - now).total_seconds() * 1000.0) | ||
|
||
# This is just a benchmark. This should NEVER take this long. | ||
assert numpy.average(timing[1:]) < 10 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
from datetime import datetime | ||
|
||
import numpy | ||
|
||
from wryte import Wryte | ||
|
||
|
||
def _test_simple_message(count): | ||
w = Wryte(color=False, simple=False) | ||
w.remove_handler('_console') | ||
timing = [] | ||
|
||
for _ in range(5): | ||
now = datetime.now() | ||
|
||
for _ in range(count): | ||
w.info('My Message') | ||
|
||
timing.append((datetime.now() - now).total_seconds() * 1000.0) | ||
|
||
return numpy.average(timing[1:]) | ||
|
||
|
||
avgs = [] | ||
|
||
for _ in range(15): | ||
result = _test_simple_message(10000) | ||
avgs.append(result) | ||
print(result) | ||
|
||
print('\navg of avgs:') | ||
print(numpy.average(avgs[1:])) | ||
|
||
# without handlers, simple message | ||
# 648e0c2: ~260ms | ||
# 764dc31: ~260ms | ||
# |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters