Tips for Fastest Code challenges

2

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.

HyperNeutrino

Posted 2017-06-19T05:28:15.623

Reputation: 26 575

Question was closed 2017-06-19T06:05:49.690

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.

– None – 2017-06-19T05:55:34.107

@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 – 2017-06-19T06:06:32.247

@HyperNeutrino It doesn't quite not exist already: https://codegolf.stackexchange.com/q/50073/8478

– Martin Ender – 2017-06-19T06:07:59.077

@MartinEnder Oh. Right, search doesn't find deleted things. Whoops. – HyperNeutrino – 2017-06-19T06:17:22.713

Related – Beta Decay – 2017-06-19T06:20:22.900

Answers

1

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.

Leaky Nun

Posted 2017-06-19T05:28:15.623

Reputation: 45 011

Hm. I never actually thought about the time wasted by higher-level languages. Nice. – HyperNeutrino – 2017-06-19T05:32:14.687

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 – 2017-06-19T12:28:18.030

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 – 2017-06-19T12:51:23.683

1There'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. – Display Name – 2017-07-05T06:08:11.823

1

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).

nore

Posted 2017-06-19T05:28:15.623

Reputation: 436