Using the ASX data. SQL to create table and index is:
create table asx (company char(3), date date, open double precision, high double precision, low double precision, close double precision, volume double precision, adjclose double precision);
// from linpack benchmark. source: http://www.netlib.org/benchmark/linpackc | |
/*----------------------*/ | |
REAL second() | |
{ | |
#include <sys/time.h> | |
#include <sys/resource.h> | |
struct rusage ru; |
module Main where | |
import qualified Data.Vector.Unboxed as U | |
import Data.List | |
import System.Random | |
import System.CPUTime | |
import Text.Printf | |
import Control.Exception | |
main :: IO () |
import Foundation; | |
protocol Num { | |
typealias T; | |
class func plus(T, T) -> T; | |
class func mul(T, T) -> T; | |
class func negate(T) -> T; | |
class func sub(T, T) -> T; | |
} |
module List | |
-- (actually List.ds but changed extension for syntax highlighting) | |
import foreign c value | |
q_string_concat : String -> String -> String | |
where | |
-- | A `Maybe` may contain a value, or not. | |
data Maybe (a : Data) where | |
Nothing : Maybe a | |
Just : a -> Maybe a |
When dealing large data sets that do not fit in memory, it is crucial to limit the number | |
of accesses and iterations over the data set. | |
However, in a high level language it may not be immediately obvious how many iterations a | |
particular program will require. | |
The number of iterations becomes even less obvious in the presence of heuristic and | |
statistics-based optimisations, as used by traditional databases: a small tweak to the query | |
or even modifying the number of rows in a table can cause drastic changes to the query plan. | |
With the advent of "big data", and as data sets continue to grow, a high level language with | |
predictable runtime characteristics becomes more necessary. |
$ ls -lah asx.psv | |
-rw-r--r-- 1 amos staff 59G 13 Nov 18:07 asx.psv | |
$ time grep -v EntryError asx.psv > /dev/null | |
real 14m33.885s | |
user 14m10.081s | |
sys 0m22.390s |
int read_bool (char *p) | |
{ | |
static const uint64_t true_mask = 0x00000000ffffffff; | |
static const uint64_t true_bits = 0x0000000065757274; | |
static const uint64_t false_mask = 0x000000ffffffffff; | |
static const uint64_t false_bits = 0x00000065736c6166; | |
static const uint64_t to_lower = 0x2020202020202020; | |
uint64_t next8 = *(uint64_t *)p | to_lower; |
/* | |
attempt at writing a faster memcmp | |
*/ | |
static iint_t INLINE memcmp8 (const char *as, const char* bs, iint_t len) | |
{ | |
uint64_t *a = (uint64_t*)as; | |
uint64_t *b = (uint64_t*)bs; | |
while (len > 8) { | |
if (*a != *b) { | |
return 1; |
#include <stdio.h> | |
#include <string.h> | |
#include <time.h> | |
typedef long long int uint64_t; | |
int cmp8_mask (const char *as, const char* bs, uint64_t len) | |
{ | |
uint64_t rem = len; | |
while (rem > 8) { |