[MRG+1] ENH: only call clock() if verbosity level warrants it #10091
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Put calls to
clock()
in routines in_barnes_hut_tsne.pyx
inside conditional statements, so thatclock()
is only called when verbosity level warrants it.This helps combat thread contention when executing TSNE in sklearn, when native extensions are compiled with icc.
Running TSNE on MNIST dataset (training + validation + test) of 70_000 hand-written images 28 by 28 pixels each, time of TSNE drops from 92 seconds to 81 seconds from this change alone.
This is the Intel (R) Vtune (TM) Amplifier snapshot with unmodified scikit-learn 0.19.1 sources, compiled with Intel (R) C Compiler, showing significant thread spinning, and
clock
being a bottleneck:running the following example
After the change, the VTune trace looks better (no thread spinning):
The execution also becomes faster, 81 seconds after the change, with 91 seconds before.