What general tips do you have for how to answer challenges?

Please post one tip per answer.

The objective of these challenges is to make the program that will run in the least amount of wall-clock time given a specific set of computer specifications (based on who will be judging the timings).

Please keep tips specific to and not ; you can assume that the coder has already found the most efficient algorithm to use.

closed as too broad by user62131, Martin Ender Jun 19 '17 at 6:05

Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • 4
    Didn't we decide, back on Meta, that this is "too broad"? You could probably host an entire Stack Exchange site about code optimization, rather than just a single question. (In fact, there's a tag on Stack Overflow on the subject which has over 20,000 questions.) EDIT: Right, here's the Meta post in question that supports the close vote. – user62131 Jun 19 '17 at 5:55
  • @ais523 Hm. I should have checked meta to see why this didn't exist already because it seems like someone should have asked this already. Thanks for the feedback! – HyperNeutrino Jun 19 '17 at 6:06
  • @HyperNeutrino It doesn't quite not exist already: codegolf.stackexchange.com/q/50073/8478 – Martin Ender Jun 19 '17 at 6:07
  • @MartinEnder Oh. Right, search doesn't find deleted things. Whoops. – HyperNeutrino Jun 19 '17 at 6:17
  • Related – Beta Decay Jun 19 '17 at 6:20

Bitwise hacks

In some cases, bit-level hacks can cut a lot of time (especially when working on small enough sets), or for larger sets, std::bitvector in C++ can help as well. Depending on the algorithm, these kind of hacks can improve the running time by a factor than can sometimes be as high as 64^2 (or even higher in some cases I have never encountered).

Language

For example, Python is an interpreted language, not a compiled language, so it would surely be faster if you wrote it in C to begin with.

Rust, C++, C, javascript, and Haskell seem to be popular choices. One would have to evaluate them.

  • Hm. I never actually thought about the time wasted by higher-level languages. Nice. – HyperNeutrino Jun 19 '17 at 5:32
  • Swift 3.1 and later with Whole-Module Optimisations or with -O(fast) can be faster that C in some cases, but can be outclassed when doing complex tasks – Mr. Xcoder Jun 19 '17 at 12:28
  • Standard ML is also a decent choice, since MLton is a whole-program optimizing compiler. As far as language design goes, Haskell gets a lot of advantages for being lazily evaluated – musicman523 Jun 19 '17 at 12:51
  • There's no such thing as an interpreted language. Implementation of a language ≠ the language itself. And Python has alternative implementations, some of them (example—PyPy) are JIT'ed. – Sarge Borsch Jul 5 '17 at 6:08

Not the answer you're looking for? Browse other questions tagged or ask your own question.