Time and Memory (noob question)

There’s probably a tutorial regarding my question, if so please point me to it.

I just completed my first successful submission on codechef. Yay me. But when I compare the run time and memory usage to the other submissions, I feel like a bit of a failure.

Can someone please take a look at CodeChef: Practical coding for everyone and explain to me why my time and memory figures are so dismal. And perhaps what I might do to improve the situation.

One thought I had, perhaps it has something to do with the language of choice. Is that a factor?

Yes the language does effect the time required. But it does not in any way effect the acceptance of the answer. Meaning, if your answer is correct and efficient, it will be accepted.

One thing you can do to speed up is use fast I/O methods. In Python, you could try speeding up your solutions by adding the following two lines to the start of your file:

import psyco

psyco.full()

Hope that helps. :slight_smile:

Thanks. I’ll go back over my submissions and try psyco to see if it makes a difference. I’m sure there is much more to learn about this and improve the way I code.

Did a little reading about psyco. Turns out it uses quite a bit of memory, though can typically speed up runtime by 4x.

That’s great but, what I really want to know is how to improve the performance of runtime and reduce memory usage at the same time. In other words some principles for writing all round efficient code. Thanks for telling me about psyco, it looks like it will be a usefull tool at some time.

1 Like

You could read about general complexity reduction from the book “Programming pearls” available freely on the internet. Typically, to reduce both memory and time requirements, choose simple data-structures such as arrays instead of objects.

Sorry I can only talk in terms of Java or even C, as I have no experience programming in python. My limited knowledge tells me that python handles many things by itself, which typically means lesser scope for small optimizations. :slight_smile:

If you feel the answer is correct, you can accept it so that the question can be closed. :slight_smile: