Created
November 23, 2012 20:22
-
-
Save cjauvin/4137131 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import time | |
from sklearn.feature_extraction.text import CountVectorizer | |
# brown20.txt is the Brown corpus concatenated 20x to itself (~1M lines) | |
# Results obtained on a 24-core Linux machine | |
start = time.time() | |
vect = CountVectorizer() | |
vect.fit_transform(open('brown20x.txt'), n_jobs=1) | |
print time.time() - start # 307 seconds | |
start = time.time() | |
vect = CountVectorizer() | |
vect.fit_transform(open('brown20x.txt'), n_jobs=-1) | |
print time.time() - start # 585 seconds (almost 2X worst) | |
start = time.time() | |
vect = CountVectorizer() | |
vect.fit_transform(open('brown20x.txt'), n_jobs=-1, batch_size=5) | |
print time.time() - start # 155 seconds | |
start = time.time() | |
vect = CountVectorizer() | |
vect.fit_transform(open('brown20x.txt'), n_jobs=-1, batch_size=10) | |
print time.time() - start # 119 seconds | |
start = time.time() | |
vect = CountVectorizer() | |
vect.fit_transform(open('brown20x.txt'), n_jobs=-1, batch_size=100) | |
print time.time() - start # 92 seconds | |
start = time.time() | |
vect = CountVectorizer() | |
vect.fit_transform(open('brown20x.txt'), n_jobs=-1, batch_size=500) | |
print time.time() - start # 88 seconds | |
start = time.time() | |
vect = CountVectorizer() | |
vect.fit_transform(open('brown20x.txt'), n_jobs=-1, batch_size=1000) | |
print time.time() - start # 86 seconds (3.5X better) | |
start = time.time() | |
vect = CountVectorizer() | |
vect.fit_transform(open('brown20x.txt'), n_jobs=2, batch_size=10000) | |
print time.time() - start # 92 seconds |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment