mirror of https://github.com/tqdm/tqdm.git
formatting fixes and minor optimisation
This commit is contained in:
parent
737df0a089
commit
13c6045fe1
|
@ -13,7 +13,7 @@ from __future__ import division, absolute_import
|
||||||
# import compatibility functions and utilities
|
# import compatibility functions and utilities
|
||||||
from ._utils import _supports_unicode, _environ_cols, _range, _unich
|
from ._utils import _supports_unicode, _environ_cols, _range, _unich
|
||||||
import sys
|
import sys
|
||||||
import time
|
from time import time
|
||||||
|
|
||||||
|
|
||||||
__author__ = {"github.com/": ["noamraph", "JackMc", "arkottke", "obiwanus",
|
__author__ = {"github.com/": ["noamraph", "JackMc", "arkottke", "obiwanus",
|
||||||
|
@ -265,7 +265,7 @@ class tqdm(object):
|
||||||
0, total, 0, ncols, self.prefix, unit, unit_scale, ascii))
|
0, total, 0, ncols, self.prefix, unit, unit_scale, ascii))
|
||||||
|
|
||||||
# Init the time/iterations counters
|
# Init the time/iterations counters
|
||||||
self.start_t = self.last_print_t = time.time()
|
self.start_t = self.last_print_t = time()
|
||||||
self.last_print_n = 0
|
self.last_print_n = 0
|
||||||
self.n = 0
|
self.n = 0
|
||||||
|
|
||||||
|
@ -296,7 +296,7 @@ class tqdm(object):
|
||||||
last_print_n = self.last_print_n
|
last_print_n = self.last_print_n
|
||||||
n = self.n
|
n = self.n
|
||||||
|
|
||||||
if self.disable:
|
if disable:
|
||||||
for obj in iterable:
|
for obj in iterable:
|
||||||
yield obj
|
yield obj
|
||||||
else:
|
else:
|
||||||
|
@ -309,9 +309,9 @@ class tqdm(object):
|
||||||
# but it would be way slower (because of method call)
|
# but it would be way slower (because of method call)
|
||||||
n += 1
|
n += 1
|
||||||
delta_it = n - last_print_n
|
delta_it = n - last_print_n
|
||||||
|
# check the counter first (avoid calls to time())
|
||||||
if delta_it >= miniters:
|
if delta_it >= miniters:
|
||||||
# We check the counter first, to reduce the overhead of time.time()
|
cur_t = time()
|
||||||
cur_t = time.time()
|
|
||||||
if cur_t - last_print_t >= mininterval:
|
if cur_t - last_print_t >= mininterval:
|
||||||
sp.print_status(format_meter(
|
sp.print_status(format_meter(
|
||||||
n, total, cur_t-start_t, ncols,
|
n, total, cur_t-start_t, ncols,
|
||||||
|
@ -324,7 +324,7 @@ class tqdm(object):
|
||||||
# Closing the progress bar
|
# Closing the progress bar
|
||||||
if leave:
|
if leave:
|
||||||
if last_print_n < n:
|
if last_print_n < n:
|
||||||
cur_t = time.time()
|
cur_t = time()
|
||||||
sp.print_status(format_meter(
|
sp.print_status(format_meter(
|
||||||
n, total, cur_t-start_t, ncols,
|
n, total, cur_t-start_t, ncols,
|
||||||
prefix, unit, unit_scale, ascii))
|
prefix, unit, unit_scale, ascii))
|
||||||
|
@ -354,8 +354,8 @@ class tqdm(object):
|
||||||
|
|
||||||
delta_it = self.n - self.last_print_n
|
delta_it = self.n - self.last_print_n
|
||||||
if delta_it >= self.miniters:
|
if delta_it >= self.miniters:
|
||||||
# We check the counter first, to reduce the overhead of time.time()
|
# We check the counter first, to reduce the overhead of time()
|
||||||
cur_t = time.time()
|
cur_t = time()
|
||||||
if cur_t - self.last_print_t >= self.mininterval:
|
if cur_t - self.last_print_t >= self.mininterval:
|
||||||
self.sp.print_status(format_meter(
|
self.sp.print_status(format_meter(
|
||||||
self.n, self.total, cur_t-self.start_t, self.ncols,
|
self.n, self.total, cur_t-self.start_t, self.ncols,
|
||||||
|
@ -372,7 +372,7 @@ class tqdm(object):
|
||||||
"""
|
"""
|
||||||
if self.leave:
|
if self.leave:
|
||||||
if self.last_print_n < self.n:
|
if self.last_print_n < self.n:
|
||||||
cur_t = time.time()
|
cur_t = time()
|
||||||
self.sp.print_status(format_meter(
|
self.sp.print_status(format_meter(
|
||||||
self.n, self.total, cur_t-self.start_t, self.ncols,
|
self.n, self.total, cur_t-self.start_t, self.ncols,
|
||||||
self.prefix, self.unit, self.unit_scale, self.ascii))
|
self.prefix, self.unit, self.unit_scale, self.ascii))
|
||||||
|
|
Loading…
Reference in New Issue