Add examples for measure time
This commit is contained in:
parent
2527c60ed0
commit
081a4fe05f
|
@ -207,6 +207,21 @@ Date and times
|
||||||
|
|
||||||
app.msgbox(app.now(True))
|
app.msgbox(app.now(True))
|
||||||
|
|
||||||
|
* Get `epoch time`_
|
||||||
|
|
||||||
|
.. code-block:: python
|
||||||
|
|
||||||
|
app.msgbox(app.get_epoch())
|
||||||
|
|
||||||
|
* Simple measure time
|
||||||
|
|
||||||
|
.. code-block:: python
|
||||||
|
|
||||||
|
app.start()
|
||||||
|
app.sleep(5)
|
||||||
|
seconds = app.end(True)
|
||||||
|
app.msgbox(seconds)
|
||||||
|
|
||||||
|
|
||||||
Thread
|
Thread
|
||||||
^^^^^^
|
^^^^^^
|
||||||
|
@ -472,3 +487,7 @@ You can save any data.
|
||||||
data = app.get_config('config', my_app)
|
data = app.get_config('config', my_app)
|
||||||
|
|
||||||
app.msgbox(data)
|
app.msgbox(data)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
.. _epoch time: https://en.wikipedia.org/wiki/Unix_time
|
||||||
|
|
|
@ -692,7 +692,7 @@ def sha512(data):
|
||||||
result = hashlib.sha512(data.encode()).hexdigest()
|
result = hashlib.sha512(data.encode()).hexdigest()
|
||||||
return result
|
return result
|
||||||
|
|
||||||
# ~ todo
|
|
||||||
def get_config(key='', prefix='conf', default={}):
|
def get_config(key='', prefix='conf', default={}):
|
||||||
name_file = FILE_NAME_CONFIG.format(prefix)
|
name_file = FILE_NAME_CONFIG.format(prefix)
|
||||||
values = None
|
values = None
|
||||||
|
@ -718,6 +718,7 @@ def set_config(key, value, prefix='conf'):
|
||||||
|
|
||||||
def start():
|
def start():
|
||||||
global _start
|
global _start
|
||||||
|
|
||||||
_start = now()
|
_start = now()
|
||||||
info(_start)
|
info(_start)
|
||||||
return
|
return
|
||||||
|
@ -725,6 +726,7 @@ def start():
|
||||||
|
|
||||||
def end(get_seconds: bool=False):
|
def end(get_seconds: bool=False):
|
||||||
global _start
|
global _start
|
||||||
|
|
||||||
e = now()
|
e = now()
|
||||||
td = e - _start
|
td = e - _start
|
||||||
result = str(td)
|
result = str(td)
|
||||||
|
@ -770,7 +772,7 @@ def url_open(url, data=None, headers={}, verify=True, get_json=False):
|
||||||
response = urlopen(req, data=data)
|
response = urlopen(req, data=data)
|
||||||
else:
|
else:
|
||||||
context = ssl._create_unverified_context()
|
context = ssl._create_unverified_context()
|
||||||
response = urlopen(req, context=context)
|
response = urlopen(req, data=data, context=context)
|
||||||
except HTTPError as e:
|
except HTTPError as e:
|
||||||
error(e)
|
error(e)
|
||||||
err = str(e)
|
err = str(e)
|
||||||
|
|
Loading…
Reference in New Issue