[BangPypers] regarding profiling

Basil Kurian basilkurian at gmail.com
Wed Oct 17 16:12:52 CEST 2012


Hi

I 'm trying out some python puzzles in interviewstreet.com. Most of the
time , when I submit my code , during testing process , it will get timed
out since the execution is taking too much time (for big input values).

I tried profiling the program execution using cprofile. Still can't
find anyoperations that is taking too much time.

Can someone help me identify the time-consuming part in the code




[bkurian at Ic3w4lker ~]$ cat xor.py
#!/usr/bin/env python
import sys

count=int(raw_input())

while count > 0:
    param=raw_input()
    param=param.split()
    param=[int(x) for x in param]

    x_arg=raw_input()
    x_arg=x_arg.split()
    x_arg=[int(x) for x in x_arg]

    val=param[1]

    while val >0:
        data=raw_input()
        data=data.split()
        data=[int(x) for x in data]
        a,p,q=data

        max=0
        for x in x_arg[p-1:q]:
            if x^a > max:
                max=x^a
        print max
        val-=1
    count-=1

[bkurian at Ic3w4lker ~]$ cat inpt
1
15 8
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
10 6 10
1023 7 7
33 5 8
182 5 10
181 1 13
5 10 15
99 8 9
33 10 14
[bkurian at Ic3w4lker ~]$ cat inpt | python -m cProfile xor.py
13
1016
41
191
191
15
107
47
         23 function calls in 0.000 seconds

   Ordered by: standard name

   ncalls  tottime  percall  cumtime  percall filename:lineno(function)
        1    0.000    0.000    0.000    0.000 xor.py:2(<module>)
        1    0.000    0.000    0.000    0.000 {method 'disable' of
'_lsprof.Profiler' objects}
       10    0.000    0.000    0.000    0.000 {method 'split' of 'str'
objects}
       11    0.000    0.000    0.000    0.000 {raw_input}


[bkurian at Ic3w4lker ~]$



-- 
Regards

Basil


More information about the BangPypers mailing list