#!/usr/bin/python2.2

import pygtk
pygtk.require("2.0")
import profile, os
import sys

if os.getcwd()[-4:] == "test":
   sys.path.append("..")
else:
   sys.path.append(".")

import mpd

music = r"""
\staff{ \time 4/4 r16 [c d e] [f d e c] [g'8 c] [b c] |
               [d16 g, a b] [c a b g] [d'8 g] [f g] |
               [e16 a g f] [e g f a] [g f e d] [c e d f] }
\staff{ \time 4/4 r2 r16 [c d e] [f d e c] |
                [g'8 g,] r4 r16 [g'16 a b] [c a b g] |
                [c8 b] [c d] [e g,] [a b] |
                }
"""
#music = r"""\staff{ c' d }"""
def vis():
        import pstats
        p = pstats.Stats("profile.txt")
        ##p.strip_dirs().sort_stats('time').print_stats(30)
        p.strip_dirs().sort_stats('cumulative').print_stats()


def pass1():
        for n in range(200):
                score = mpd.parser.parse_to_score_object(music)
                #eng = score.get_engravers(20)
def pass2():
    for x in range(20):
        score = mpd.parser.parse_to_score_object(music)
        eng = score.get_engravers(20)

import time
t1 = time.clock()
if 0:
    os.system("rm -f profile.txt")
    profile.run("pass2()", "profile.txt")
    vis()
else:
    #import gc
    #gc.set_debug(gc.DEBUG_LEAK)
    pass1()
    #gc.collect()
t2 = time.clock()
print t2-t1

