Ishu Gupta
Ishu Gupta

Reputation: 1101

Total time used by a method after multiple calls

For a large file I am calling the following regex module in python in a for loop (depending on the number of rows in a file ) . I just want to find out what is the total time (for all the calls) consumed by this operation

re.sub(record_read_regex, output_fmt, currentline)

I can not put a timer before and after for loop as I am performing other operations in it .

Upvotes: 0

Views: 41

Answers (1)

syntagma
syntagma

Reputation: 24334

I can not put a timer before and after for loop as I am performing other operations in it.

But you can put timer before and after statement you want to measure:

import timeit
total_elapsed = 0

for i in your_iterator:
    start_time = timeit.default_timer()
    re.sub(record_read_regex, output_fmt, currentline)
    elapsed = timeit.default_timer() - start_time
    total_elapsed = total_elapsed + elapsed

Upvotes: 2

Related Questions