0

count = 10, 100, 1000, 10000

for each value of count, i need to execute the method 5 times using timeit and print out the min value and the actual 5 values.

numstring contains four functions in it.

output should look like (a total of 16 lines):

numbers_string1, count = 10, min = 0.0001, actuals = [0.0001, 0.0002, 0.0001, ...]

numbers_string1, count = 100, min = 0.002, actuals = [0.002, 0.002, 0.003, ...]

....

numbers_string4, count = 10000, min = 0.1 actuals = [....]

For this i tried this way:

My Code:

from numstring import *
import timeit

def profile_timeit():
    funcs_list = [numbers_string1, numbers_string2, numbers_string3, num_strings4]
    for i in funcs_list:
        for count in [10, 100, 1000, 10000]:
            actuals = timeit.timeit(stmt='i(count)', number=4, setup='from __main__ import *')
            print "{0} count = {1} \t min = {2} \t actuals = {3}".format(i, count, min(actuals), actuals)
        print "\n"
if __name__ == "__main__":
    profile_timeit()

can anybody please help me out. Thanks in advance

1 Answer 1

1

could you try this....

from numstring import *
import timeit
def profile_timeit():
    funcs = [numbers_string1,numbers_string2,numbers_string3,num_strings4]
    count = [10,100,1000,10000]
    for func in funcs:
        for cnt in count:
            for i in xrange(5):
                t=timeit.Timer(stmt = "%s(%d)"%(func.__name__, cnt), setup = "from __main__ import %s"%(func.__name__, ))
                tms = t.repeat(repeat=5, number=1)
            print "%s, count = %d, min = %s , actuals = %s" % (func.__name__, cnt, min(tms), tms)
    pass

tell me if it is ok or not?

Sign up to request clarification or add additional context in comments.

1 Comment

hello abdullah can you explain me how to do the project?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.