Created
July 7, 2014 16:45
-
-
Save cjmcgraw/ff23f963e62c827adc7a to your computer and use it in GitHub Desktop.
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 random import randint | |
from time import time | |
VALUE_RANGE = (0, 1000) | |
def timer(f): | |
def wrapper(first_list, second_list, required_difference): | |
t1 = time() | |
result = f(first_list, second_list, required_difference) | |
t2 = time() | |
n = len(first_list) | |
print("executing the function with {} values took ----> {} seconds".format(n, t2 - t1)) | |
return result | |
return wrapper | |
def test_setup(n): | |
first_list = [randint(*VALUE_RANGE) for x in range(n)] | |
second_list = [randint(*VALUE_RANGE) for x in range(n)] | |
return first_list, second_list | |
@timer | |
def test_function(first_list, second_list, required_difference): | |
result = 0; | |
for x in first_list: | |
for y in second_list: | |
if (x - y) == required_difference: result+= 1 | |
return result | |
def run_test_suite(): | |
for n in range(1, 100, 10): | |
f, s = test_setup(n) | |
result = test_function(f, s, 2) | |
print(" Number of values found meeting the requirement: {}".format(result)) | |
print("") | |
if __name__=="__main__": | |
run_test_suite() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment