0
[SOLVED] How to reduce time limit while performing operations on 10000 inputs from user in python3??
Tle
8 Respuestas
+ 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.
+ 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.
+ 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.)
+ 1
Thanks..
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
0
Aim is to perform EXOR operation on each element in list
0
Are you taking 10,000 user inputs at once?