import os
import time

class benchmark(object):
    def __init__(self, name):
        self._name = name

    def __call__(self, func):
        def wrapper(*args, **kwargs):
            start = time.clock()
            func(*args, **kwargs)
            end = time.clock()
            return end - start
        wrapper.__name__ = func.__name__
        return wrapper


@benchmark('mistune')
def benchmark_mistune(text):
    import mistune
    mistune.markdown(text)


@benchmark('misaka')
def benchmark_misaka(text):
    import misaka as m
    # mistune has all these features
    extensions = (
        m.EXT_NO_INTRA_EMPHASIS | m.EXT_FENCED_CODE | m.EXT_AUTOLINK |
        m.EXT_TABLES | m.EXT_STRIKETHROUGH
    )
    md = m.Markdown(m.HtmlRenderer(), extensions=extensions)
    md.render(text)


@benchmark('markdown2')
def benchmark_markdown2(text):
    import markdown2
    extras = ['code-friendly', 'fenced-code-blocks', 'footnotes']
    markdown2.markdown(text, extras=extras)


@benchmark('markdown')
def benchmark_markdown(text):
    import markdown
    markdown.markdown(text, ['extra'])


@benchmark('cMarkdown')
def benchmark_cMarkdown(text):
    import cMarkdown
    cMarkdown.markdown(text)


@benchmark('discount')
def benchmark_discount(text):
    import discount
    discount.Markdown(text).get_html_content()


if __name__ == '__main__':
    root = os.path.dirname(__file__)
    filepath = os.path.join(
        root, 'cases', 'markdown_documentation_syntax.text'
    )
    with open(filepath, 'r') as f:
        text = f.read()

    loops = 1000

    totals = []
    methods = [
        ('Mistune', benchmark_mistune),
        ('Misaka', benchmark_misaka),
        ('Markdown', benchmark_markdown),
        ('Markdown2', benchmark_markdown2),
        ('cMarkdown', benchmark_cMarkdown),
        ('Discount', benchmark_discount),
    ]

    print('Parsing the Markdown Syntax document %d times...' % loops)
    for name, fn in methods:
        try:
            total = 0
            for i in range(loops):
                total += fn(text)
            print('{0}: {1}'.format(name, total))
        except ImportError:
            print('{0} is not available'.format(name))

@@ -1322,16 +1322,353 @@
 ent()%0A%0A%0A
+@benchmark('hoep')%0Adef benchmark_hoep(text):%0A    import hoep as m%0A    # mistune has all these features%0A    extensions = (%0A        m.EXT_NO_INTRA_EMPHASIS %7C m.EXT_FENCED_CODE %7C m.EXT_AUTOLINK %7C%0A        m.EXT_TABLES %7C m.EXT_STRIKETHROUGH %7C m.EXT_FOOTNOTES%0A    )%0A    md = m.Hoep(extensions=extensions)%0A    md.render(text.decode('utf-8'))%0A%0A%0A
 if __nam
@@ -2178,16 +2178,50 @@
 count),%0A
+        ('Hoep', benchmark_hoep),%0A
     %5D%0A%0A 

Add benchmark for hoep