[Latest update: benchmark program and preliminary resuls available, see below]
So I want to test the speed/complexity tradeoff with a classic application: sorting.
Write an ANSI C function that sorts an array of floating point numbers in increasing order.
You can't use any libraries, system calls, multithreading or inline ASM.
Entries judged on two components: code length and performance. Scoring as follows: entries will be sorted by length (log of #characters without whitespace, so you can keep some formatting) and by performance (log of #seconds over a benchmark), and each interval [best,worst] linearly normalised to [0,1]. The total score of a program will be the average of the two normalised scores. Lowest score wins. One entry per user.
Sorting will have to (eventually) be in place (i.e. the input array will have to contain sorted values at return time), and you must use the following signature, including names:
void sort(float* v, int n) {
}
Characters to be counted: those in the sort
function, signature included, plus additional functions called by it (but not including testing code).
The program must handle any numeric value of float
and arrays of length >=0, up to 2^20.
I'll plug sort
and its dependencies into a testing program and compile on GCC (no fancy options). I'll feed a bunch of arrays into it, verify correctness of results and total run time. Tests will be run on an Intel Core i7 740QM (Clarksfield) under Ubuntu 13.
Array lengths will span the whole allowed range, with a higher density of short arrays. Values will be random, with a fat-tail distribution (both in the positive and negative ranges). Duplicated elements will be included in some tests.
The test program is available here: https://gist.github.com/anonymous/82386fa028f6534af263
It imports the submission as user.c
. The number of test cases (TEST_COUNT
) in the actual benchmark will be 3000. Please provide any feedback in the question comments.
Deadline: 3 weeks (7 April 2014, 16:00 GMT). I will post the benchmark in 2 weeks.
It may be advisable to post close to the deadline to avoid giving away your code to competitors.
Preliminary results, as of benchmark publication:
Here are some results. The last column shows the score as a percentage, the higher the better, putting Johnny Cage in first place. Algorithms that were orders of magnitude slower than the rest were run on a subset of tests, and time extrapolated. C's own qsort
is included for comparison (Johnny's is faster!). I'll perform a final comparison at closing time.