<commit_before><commit_msg>A script for benchmarking certain ways of doing things - in this case,  different ways of fetching results.<commit_after>import sys
import os
sys.path.insert(0, os.getcwd())

from intermine.webservice import Service
import time

s = Service("localhost/intermine-test")
lazy = s.select("Department.*")
eager = s.select("Department.*", "Department.employees.*")

def do_work(q):
    res = q.results()
    age_sum = reduce(lambda x, y: x + reduce(lambda a, b: a + b.age, y.employees, 0), res, 0)
    assert(age_sum == 5798)

if __name__ == '__main__':
    tests = {"Lazy": lazy, "Eager": eager}
    n = 10
    print "Benchmarking %d iterations of " % n + ", ".join(tests.keys())
    for label, q in tests.iteritems():
        total = 0
        for t in range(n):
            a = time.time()
            do_work(q)
            b = time.time()
            total += b - a
        print "%s: total %s, avg: %s" % (label, total, total/n)

{'fraction_non_alphanumeric': 0.14733542319749215, 'fraction_numerical': 0.01044932079414838, 'mean_word_length': 2.8015873015873014, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5042316', 'n_tokens_mistral': 335, 'n_tokens_neox': 319, 'n_words': 100}