Created
August 14, 2013 13:22
-
-
Save tomas-edwardsson/6230958 to your computer and use it in GitHub Desktop.
Tests for pynag.Model performance tests
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
from pynag import Model, Utils | |
from time import time | |
import sys | |
progress = False | |
def main(): | |
global progress | |
services = get_host_service_tuples() | |
# test filters | |
for otype in [ | |
'object', | |
'grep objects.all from within loop', | |
'grep with objects.all outside loop']: | |
print "Testing %s filtering" % otype | |
start = time() | |
i = 0 | |
service_objects = [] | |
if otype == 'grep with objects.all outside loop': | |
service_objects = Model.Service.objects.all | |
for s in services: | |
if progress: | |
i += 1 | |
if not i % 10: | |
sys.stdout.write(".") | |
sys.stdout.flush() | |
if otype == 'object': | |
Model.Service.objects.filter(host_name=s[0], | |
service_description=s[1]) | |
elif otype == 'grep objects.all from within loop': | |
Utils.grep(Model.Service.objects.all, | |
host_name=s[0], | |
service_description=s[1]) | |
elif otype == 'grep with objects.all outside loop': | |
Utils.grep(service_objects, | |
host_name=s[0], | |
service_description=s[1]) | |
if progress: | |
print "" | |
print "% 6i %.2f seconds" % (len(services), time() - start) | |
def get_host_service_tuples(): | |
"""Returns [ | |
( 'host1', 'service description1' ), | |
( 'host1', 'service description2' ), | |
( 'host2', 'service description1' ) ] | |
""" | |
service_tuples = [] | |
for s in Model.Service.objects.all: | |
if s['host_name'] and s['service_description']: | |
service_tuples.append((s['host_name'], s['service_description'])) | |
return service_tuples | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment