Sorting a Billion Numbers with Julia
mikeinnes.github.io
mikeinnes.github.io
It's not ready for prime time, but:
Time to sum 1,000,000,000 floats: 1.5 seconds
Time to sort 1,000,000,000 floats: 30.5 seconds
The code to fill a column and sort it:
FloatColumn fc = new FloatColumn("test", 1_000_000_000);
for (int i = 0; i < 1_000_000_000; i++) {
fc.add((float) Math.random());
}
fc.sortAscending(); $ go run billion.go
1m32.471498831s
Where billion.go goes: package main
import (
"fmt"
"math/rand"
"time"
"github.com/twotwotwo/sorts/sortutil"
)
func main() {
floats := make([]float64, 1<<30)
for i := range floats {
floats[i] = rand.Float64()
}
t := time.Now()
sortutil.Float64s(floats)
fmt.Println(time.Now().Sub(t))
}
Out-of-core stuff's cool, and sometimes seems a shame it's not available directly (rather than by exporting data to some other program) and widely used in more programming environments.Glad original poster's experimenting and got something about external sorting up here.
Tablesaw's not out of core either: too much of a pain (for me) to work with variable width columns like text that way.
I just tried on Spark master branch (i.e. the work-in-progress code for Spark 2.0). It takes about 1.5 secs to sum up 1 billion 64-bit integers using a single thread, and about 1 secs using 2 threads. This was done on my laptop (Early 2015 Macbook Pro 13, 3.1GHz Intel Core i7).
We haven't optimized integer sorting yet, so that's probably not going to be super fast, but the aggregation performance has been pretty good.
scala> val start = System.nanoTime
start: Long = 56832659265590
scala> sqlContext.range(0, 1000L * 1000 * 1000, 1, 2).count()
res8: Long = 1000000000
scala> val end = System.nanoTime
end: Long = 56833605100948
scala> (end - start) / 1000 / 1000
res9: Long = 945
Part of the time are actually spent analyzing the query plan, optimizing it, and generating bytecode for it. If we run this on 10 billion integers, the time is about 5 secs.MMAP'd from HDD 1st run - 47s
MMAP'd from HDD 2nd run - 1.35s (OS caches pages in memory)
MMAP'd from NVMe 1st run - 6.5s (OS Caches dropped)
MMAp'd from NVMe 2nd run 1.35s (OS cached again)
When you start searching the resultant sorted list, it might be somewhat slower than if you sorted using other techniques, but--silver lining--search times will only improve after that!
I'd give you the actual stats but so far I've only lazy evaluated them.
For example, a priority queue (list of tasks) does not need to be fully sorted, only sorted to the extent that the highest priorty item is quickly determinable, and there are algorithms and data structures designed for this behavior.
Sorting (other than to print a sorted list) doesn't pay for itself till you do a number of searches, and associative memory hashes are frequently better if you simply wish to find exact matches again. Even the lowly bubble sort has the not-insignificant benefit of finding the first value in O(n) time which may be the behavior you need: lazy evaluation can be the exact right way to go if you are instructed to sort, as you await more info as to what the appropriate technique might be.
I think humor is only funny when it's based on truthiness.
What matters when sorting a billion numbers is wallclock runtime from the start of the sort to the end of materialization (see http://sortbenchmark.org/) or iteration. And it means, almost always, materializing or iterating the entire result set.
it's not clear to me any haskell programs have won any real awards in sorting modest amounts of data, since you have to visit all the data and compare nlogn times.
Or until you absolutely need to iterate thru a collection in sorted order.
If you need a priority queue, use a priority queue, if you need a sorted container, use a sorted container.
But that's pretty much what you've done/contributed.
Of course lazy evaluation is faster if it's so lazy it doesn't actually evaluate anything/does something completely different to the original problem.
Now evaluate it and come back with a wall time...
But you already knew that - you just hadn't evaluated it yet.