0

[SOLVED] How to reduce time limit while performing operations on 10000 inputs from user in python3??

Tle

7th Mar 2020, 2:59 PM
Pratik Kumbhar
Pratik Kumbhar - avatar
8 ответов
+ 1
from timeit import timeit from random import randint def f(): l=[randint(1, 100) for i in range(10000)] p=randint(1, 10) l1=[] for i in l: h=i^p l1.append(h) def g(): p=randint(1, 10) l1=[randint(1, 100)^p for i in range(10000)] print(timeit(f, number=100)) print(timeit(g, number=100)) To do any sort of testing, you need to create a setting that's testable. You'll hardly find people inputting 10000 values for you. So I have tried to instead create 10000 random values. In one function I use your calculate-and-append mode, in another I create a list comp directly. Then I test both functions with timeit to see which runs faster. It seems to me that the listcomp version is slightly faster. You can copy the pattern: Make different algos for the same task, then run them with timeit to test which one performs better.
7th Mar 2020, 4:09 PM
HonFu
HonFu - avatar
+ 2
That's a question that is absolutely case-based. Do you want to transform the user input into an int? Or do you want to transform the user input into a chess move and calculate if it's checkmate? Obviously one will take longer. ;-) So in order to help you, we need details. Show us your code, then we can try to find ways to make it quicker.
7th Mar 2020, 3:04 PM
HonFu
HonFu - avatar
+ 1
What is the aim of the code? What are you planning to do eventually? And can you link it? (Again: Performance optimization is code-specific.)
7th Mar 2020, 3:08 PM
HonFu
HonFu - avatar
+ 1
Thanks..
7th Mar 2020, 5:12 PM
Pratik Kumbhar
Pratik Kumbhar - avatar
0
I am going to perfrom exor operation between a number and each element in list.... But the problem is the list is of 100000 elements.... So the result is TLE
7th Mar 2020, 3:07 PM
Pratik Kumbhar
Pratik Kumbhar - avatar
0
Aim is to perform EXOR operation on each element in list
7th Mar 2020, 3:10 PM
Pratik Kumbhar
Pratik Kumbhar - avatar
7th Mar 2020, 3:20 PM
Pratik Kumbhar
Pratik Kumbhar - avatar
0
Are you taking 10,000 user inputs at once?
7th Mar 2020, 3:56 PM
HonFu
HonFu - avatar