|
|||||
|
|
#1 |
|
|
I am trying to improve my programming skills. I read an article or book about that and the author suggests to solve problems from programming challenges and programming contest online. I can't remember the programming contest website in the book. I am looking for the questions that would help me to learn how to optimize my code. I am not looking for the long and confusing questions from contest like ACM. The website from the books has questions with only a couple of lines and people from around the world can submit their answers independently online. Then the rank is determined by how fast their code run. I can't seem to find the site anymore ![]() So, does anyone know any contest website that has questions related to code optimization? Thanks |
|
|
#2 |
|
|
> Hi All > I am trying to improve my programming skills. I read an article or > book about that and the author suggests to solve problems from > programming challenges and programming contest online. > > I can't remember the programming contest website in the book. > > I am looking for the questions that would help me to learn how to > optimize my code. Here they are. Q1) Do you need to optimise your code? A1) Probably not, except for readability. Q2) When might you need to optimise your code for space? A2) When it's too big, which will probably never happen, so don't bother. Q3) When might you need to optimise your code for speed? A3) When it's too slow, which might conceivably happen. Q4) When the code *is* too slow, what optimisation will have the biggest impact? A4) Better algorithm choice. Q5) When is the best time to choose good algorithms? A5) Before writing the first version. So, if you do this right, your very first cut will already be optimised. -- Richard Heathfield "Usenet is a strange place" - dmr 29/7/1999 http://www.cpax.org.uk email: rjh at the above domain, - www. |
|
|
#3 |
|
|
> tiger66 said: > >> Hi All >> I am trying to improve my programming skills. I read an article or >> book about that and the author suggests to solve problems from >> programming challenges and programming contest online. >> >> I can't remember the programming contest website in the book. >> >> I am looking for the questions that would help me to learn how to >> optimize my code. > > Here they are. > > Q1) Do you need to optimise your code? > A1) Probably not, except for readability. > > Q2) When might you need to optimise your code for space? > A2) When it's too big, which will probably never happen, so don't > bother. > > Q3) When might you need to optimise your code for speed? > A3) When it's too slow, which might conceivably happen. > > Q4) When the code *is* too slow, what optimisation will have the biggest > impact? > A4) Better algorithm choice. > > Q5) When is the best time to choose good algorithms? > A5) Before writing the first version. So, if you do this right, your > very first cut will already be optimised. It's not always that easy. There are often different good algorithms for different sizes and shapes of input-- you might write a renderer for example that was very fast for large numbers of small triangles but very slow for small numbers of big ones. You don't always know what size and shape the input will be until the first version of the system is running. Or you might just have miscalculated or under- or over-estimated something. Choosing good algorithms for jobs that don't need them can cost time and introduce bugs giving you less time to find out where the effort really needs to be spent. Sometimes the good algorithms have a setup time or an overhead that makes them perform worse in the real system when N turns out to be small. Usually the first version should just be the simplest and clearest thing possible that works. |
|
|
#4 |
|
|
Richard Heathfield wrote:
> tiger66 said: > > >>Hi All >>I am trying to improve my programming skills. I read an article or >>book about that and the author suggests to solve problems from >>programming challenges and programming contest online. >> >>I can't remember the programming contest website in the book. >> >>I am looking for the questions that would help me to learn how to >>optimize my code. > > > Here they are. > > Q1) Do you need to optimise your code? > A1) Probably not, except for readability. > > Q2) When might you need to optimise your code for space? > A2) When it's too big, which will probably never happen, so don't > bother. > > Q3) When might you need to optimise your code for speed? > A3) When it's too slow, which might conceivably happen. > > Q4) When the code *is* too slow, what optimisation will have the biggest > impact? > A4) Better algorithm choice. > > Q5) When is the best time to choose good algorithms? > A5) Before writing the first version. So, if you do this right, your > very first cut will already be optimised. Q6) My program is slow. Which part needs optimising? A6) Ask your profiler where the program is spending its time. That is probably a good place to optimise. A real example I have heard about is a turn-based RPG where there was a nasty 1/2-second delay between pressing the key and the new situation being displayed. This delay was reduced to imperceptibility by changing the algorithm used for set union. Lesson: if it is slow, profile. -- Simon Richard Clarkstone: s.r.cl?rkst?n?@durham.ac.uk/s?m?n.cl?rkst?n?@hotmail.com "August 9 - I just made my signature file. Its only 6 pages long. I will have to work on it some more." -- _Diary of an AOL User_ |
|
|
#5 |
|
|
Simon Richard Clarkstone said:
<snip> > Q6) My program is slow. Which part needs optimising? > A6) Ask your profiler where the program is spending its time. That is > probably a good place to optimise. An excellent addition. And the way in which to optimise is almost always to use a better algorithm, rather than indulge in techniques such as loop-unrolling, common subexpression elimination, etc, which the compiler ought to be doing for you anyway. <snip> > Lesson: if it is ....too... > slow, profile. Aye. -- Richard Heathfield "Usenet is a strange place" - dmr 29/7/1999 http://www.cpax.org.uk email: rjh at the above domain, - www. |