~snowball-yiddish-dev/snowball-yiddish/trunk

« back to all changes in this revision

Viewing changes to pystemmer/benchmark.py

  • Committer: Jason Spashett
  • Date: 2012-04-14 13:12:57 UTC
  • Revision ID: jason@spashett.com-20120414131257-rv3ugy4u2iyoczdk
Add ISO 639-2, and 639-1 language codes

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env python
 
2
 
 
3
# This script runs a simple benchmark of the python stemmer interface.
 
4
 
 
5
import timeit
 
6
 
 
7
datafiles = ('sampledata/englishvoc.txt', 'sampledata/puttydoc.txt',)
 
8
words_lst = [None]
 
9
 
 
10
for datafile in datafiles:
 
11
    words = []
 
12
    for line in open(datafile):
 
13
        words.extend(line.split())
 
14
    for cache_size in (0, 1, 10000, 30000):
 
15
        setup = r"""
 
16
import Stemmer
 
17
stemmer = Stemmer.Stemmer('en', %d)
 
18
words = []
 
19
for line in open('%s'):
 
20
    words.extend(line.split())
 
21
""" % (cache_size, datafile)
 
22
        t = timeit.Timer(setup=setup,
 
23
                         stmt='stemmer.stemWords(words)')
 
24
        for iters in (1, 2, 3, 10):
 
25
            times = [time / iters for time in t.repeat(5, iters)]
 
26
            print "'%s':words=%d,cacheSize=%d,iters=%d,mintime=%f" % (datafile, len(words), cache_size, iters, min(times))