From: noah morrison Date: Tue, 18 Nov 2014 18:13:22 +0000 (-0500) Subject: Added a benchmark X-Git-Url: https://git.devinivas.org/?a=commitdiff_plain;h=ee0d533f9ada9d56febfb19f8d422ff153ae83d3;p=chevron.git Added a benchmark currently running ./benchmark will return around 1.3631531159917358 --- diff --git a/benchmark.py b/benchmark.py new file mode 100755 index 0000000..e5e9452 --- /dev/null +++ b/benchmark.py @@ -0,0 +1,83 @@ +#!/usr/bin/python +# coding: utf-8 + +from sys import argv +from timeit import timeit + +import chevron + + +def make_test(template=None, data=None, expected=None): + def test(): + result = chevron.render(template, data) + if result != expected: + error = 'Test failed:\n-- got --\n{}\n-- expected --\n{}' + raise Exception(error.format(result, expected)) + + return test + + +def main(times): + args = { + 'template': """\ +{{# comments }} +
+ {{ user }} + {{ body }} + {{ vote }} +
+{{/ comments }} +""", + 'data': { + 'comments': [ + {'user': 'tommy', + 'body': 'If this gets to the front page I\'ll eat my hat!', + 'vote': 625}, + + {'user': 'trololol', + 'body': 'this', + 'vote': -142}, + + {'user': 'mctom', + 'body': 'I wish thinking of test phrases was easier', + 'vote': 83}, + + {'user': 'the_thinker', + 'body': 'Why is /u/trololol\'s post higher than ours?', + 'vote': 36} + ] + }, + 'expected': """\ +
+ tommy + If this gets to the front page I'll eat my hat! + 625 +
+
+ trololol + this + -142 +
+
+ mctom + I wish thinking of test phrases was easier + 83 +
+
+ the_thinker + Why is /u/trololol's post higher than ours? + 36 +
+""" + } + + test = make_test(**args) + + print(timeit(test, number=times)) + + +if __name__ == '__main__': + try: + main(int(argv[1])) + except IndexError: + main(10000)