kenkovlog

けんこふたんっオフィシャユブヨグッ
アンッ!アンッ!アンッ!アンッ!

Benchmark in Python

Benchmarker is a useful module when we want to take a benchmark.

Install

$ sudo pip install ez_setup
$ sudo pip install Benchmarker

How To

I wrote a test code; test.py for my IBMmodel2.

#! /usr/bin/env python
# coding:utf-8

from __future__ import division, print_function
import sys
import sqlite3
import keitaiso
from operator import itemgetter
sys.path.append("../")
import ibmmodel2


con = sqlite3.connect(":db:")
cur = con.cursor()
cur.execute("select * from jec_basic_sentence limit 1000")
sent_pairs = []
for item in cur:
    #print(item[0].encode('utf-8'), item[1].encode('utf-8'))
    japanese = keitaiso.str2wakati(item[0])
    english = item[1]
    sent_pairs.append((japanese, english))

from benchmarker import Benchmarker
with Benchmarker(width=20) as bm:
    with bm('loop_count=100, limit=1000'):
        t, a = ibmmodel2.train(sent_pairs, loop_count=100)

I issued the following command.

$ python test.py
## benchmarker:       release 3.0.1 (for python)
## python platform:   darwin [GCC 4.2.1 Compatible Apple Clang 4.0 (tags/Apple/clang-418.0.60)]
## python version:    2.7.2
## python executable: /usr/bin/python

##                       user       sys     total      real
loop_count=100, l...  61.1000    0.0900   61.1900   61.2366

## Ranking               real
loop_count=100, limit=1000  61.2366 (100.0%) *************************

## Ratio Matrix          real    [01]
[01] loop_count=100, limit=1000  61.2366  100.0%
けんこふたん