Measure time for different stages
This commit is contained in:
parent
d2a256957f
commit
8492d0c1e5
@ -4,6 +4,7 @@ Created on 11. 06. 2016
|
||||
@author: wn
|
||||
'''
|
||||
|
||||
from __future__ import print_function
|
||||
|
||||
import xlrd
|
||||
import xlwt
|
||||
@ -11,6 +12,8 @@ from xlutils.copy import copy
|
||||
import pymongo
|
||||
from bson.son import SON
|
||||
import datetime
|
||||
import time
|
||||
|
||||
|
||||
DBHOST = '172.16.2.17'
|
||||
DBNAME = 'iot'
|
||||
@ -43,6 +46,19 @@ PIPELINE = [
|
||||
]
|
||||
|
||||
|
||||
class Stopwatch():
|
||||
def millis(self):
|
||||
return time.time() * 1000
|
||||
def __init__(self, msg):
|
||||
self.msg = msg
|
||||
def __enter__(self):
|
||||
self.start = self.millis()
|
||||
print("{} ... ".format(self.msg), end="")
|
||||
def __exit__(self, type, value, traceback):
|
||||
duration = self.millis() - self.start
|
||||
print("{}".format(duration))
|
||||
|
||||
|
||||
class DataAdder(object):
|
||||
def __init__(self, dbhost, dbname, dbcoll, filename, pipeline):
|
||||
self.dbhost = dbhost
|
||||
@ -71,23 +87,21 @@ class DataAdder(object):
|
||||
return cursor
|
||||
|
||||
def run(self):
|
||||
print("stage 1")
|
||||
self.openExcel()
|
||||
print("stage 2")
|
||||
with Stopwatch("stage 1: collecting data"):
|
||||
cursor = self.collectData()
|
||||
print("stage 3")
|
||||
with Stopwatch("stage 2: opening excel"):
|
||||
self.openExcel()
|
||||
with Stopwatch("stage 3: writing excel"):
|
||||
for rownum, row in enumerate(cursor):
|
||||
print(rownum)
|
||||
if (rownum == 0):
|
||||
for pos, key in enumerate(row.iterkeys()):
|
||||
self.sheetW.write(rownum, pos, key)
|
||||
else:
|
||||
for pos, value in enumerate(row.itervalues()):
|
||||
if (pos == 0):
|
||||
v = str(value)
|
||||
else:
|
||||
v = value
|
||||
self.sheetW.write(rownum, pos, v)
|
||||
if (type(value) not in [int, float]):
|
||||
value = str(value)
|
||||
self.sheetW.write(rownum, pos, value)
|
||||
with Stopwatch("stage 4: saving excel"):
|
||||
self.excelW.save(self.filename)
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user