forked from matomo-org/matomo
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
provide a sample test to benchmark the impact of caching the dates
As a reference on a laptop with : Intel(R) Core(TM) i7-2630QM CPU @ 2.00GHz Python 2.7.7rc1 Debian SID - Linux 3.14-1-amd64 matomo-org#1 SMP Debian 3.14.4-1 (2014-05-13) x86_64 GNU/Linux The results are : cache : 647.914 ms nocache : 21440.542 ms
- Loading branch information
Showing
2 changed files
with
1,000,046 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
#!/usr/bin/env python | ||
|
||
import datetime | ||
import time | ||
from collections import OrderedDict | ||
|
||
date_format = '%d/%b/%Y:%H:%M:%S' | ||
|
||
def timing(f): | ||
def wrap(*args): | ||
time1 = time.time() | ||
ret = f(*args) | ||
time2 = time.time() | ||
print '%s\t: %0.3f ms' % (f.func_name, (time2-time1)*1000.0) | ||
return ret | ||
return wrap | ||
|
||
@timing | ||
def nocache(): | ||
file = open("timestamps.log", 'r') | ||
for lineno, line in enumerate(file): | ||
date_string, timezone_string = line.split() | ||
|
||
date = datetime.datetime.strptime(date_string, date_format) | ||
timezone = float(timezone_string) | ||
|
||
date -= datetime.timedelta(hours=timezone/100) | ||
|
||
@timing | ||
def cache(): | ||
cache_dates = OrderedDict() | ||
file = open("timestamps.log", 'r') | ||
for lineno, line in enumerate(file): | ||
date_string, timezone_string = line.split() | ||
key = line | ||
|
||
date = cache_dates.get(key) | ||
if not date: | ||
date = datetime.datetime.strptime(date_string, date_format) | ||
timezone = float(timezone_string) | ||
|
||
date -= datetime.timedelta(hours=timezone/100) | ||
cache_dates[key] = date | ||
|
||
cache() | ||
nocache() |
Oops, something went wrong.