Skip to content

Commit

Permalink
better replacement of deprecated .clock()
Browse files Browse the repository at this point in the history
  • Loading branch information
gojomo committed Jan 27, 2020
1 parent 4710308 commit d05259a
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 12 deletions.
6 changes: 3 additions & 3 deletions gensim/corpora/sharded_corpus.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,12 +280,12 @@ def init_shards(self, output_prefix, corpus, shardsize=4096, dtype=_default_dtyp
self.dim = proposed_dim
self.offsets = [0]

start_time = time.clock()
start_time = time.perf_counter()

logger.info('Running init from corpus.')

for n, doc_chunk in enumerate(gensim.utils.grouper(corpus, chunksize=shardsize)):
logger.info('Chunk no. %d at %f s', n, time.clock() - start_time)
logger.info('Chunk no. %d at %f s', n, time.perf_counter() - start_time)

current_shard = numpy.zeros((len(doc_chunk), self.dim), dtype=dtype)
logger.debug('Current chunk dimension: %d x %d', len(doc_chunk), self.dim)
Expand All @@ -300,7 +300,7 @@ def init_shards(self, output_prefix, corpus, shardsize=4096, dtype=_default_dtyp

self.save_shard(current_shard)

end_time = time.clock()
end_time = time.perf_counter()
logger.info('Built %d shards in %f s.', self.n_shards, end_time - start_time)

def init_by_clone(self):
Expand Down
11 changes: 2 additions & 9 deletions gensim/models/hdpmodel.py
Original file line number Diff line number Diff line change
Expand Up @@ -464,10 +464,7 @@ def update(self, corpus):
"""
save_freq = max(1, int(10000 / self.chunksize)) # save every 10k docs, roughly
chunks_processed = 0
try:
start_time = time.time()
except AttributeError:
start_time = time.clock()
start_time = time.perf_counter()

while True:
for chunk in utils.grouper(corpus, self.chunksize):
Expand Down Expand Up @@ -511,16 +508,12 @@ def update_finished(self, start_time, chunks_processed, docs_processed):
If True - model is updated, False otherwise.
"""
try:
start_time = time.time()
except AttributeError:
start_time = time.clock()
return (
# chunk limit reached
(self.max_chunks and chunks_processed == self.max_chunks)

# time limit reached
or (self.max_time and start_time - start_time > self.max_time)
or (self.max_time and time.perf_counter() - start_time > self.max_time)

# no limits and whole corpus has been processed once
or (not self.max_chunks and not self.max_time and docs_processed >= self.m_D))
Expand Down

0 comments on commit d05259a

Please sign in to comment.