Skip to content

Instantly share code, notes, and snippets.

@gregorycollins
gregorycollins / ensure.hs
Created October 19, 2011 19:20
Evaluation, bang patterns, and deepseq
{-# LANGUAGE CPP, BangPatterns #-}
module Main where
import Control.DeepSeq
import Data.List
ensure :: [Int] -> IO [Int]
ensure xs = xs `deepseq` return xs
@gregorycollins
gregorycollins / Config.hs
Created June 17, 2011 00:04
new config.hs
{-# LANGUAGE CPP #-}
{-# LANGUAGE OverloadedStrings #-}
{-|
This module exports the 'Config' datatype, which you can use to configure the
Snap HTTP server.
-}
@gregorycollins
gregorycollins / BitTwiddle.hs
Created May 11, 2011 20:58
Bit twiddling in haskell vs. C
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE MagicHash #-}
{-# LANGUAGE ForeignFunctionInterface #-}
module Main where
import Criterion
import Criterion.Main
import Data.Bits
import Foreign.C
@gregorycollins
gregorycollins / EnumeratorFork.hs
Created April 20, 2011 19:12
Forking an enumerator computation
{-# LANGUAGE ScopedTypeVariables #-}
import Control.Concurrent (killThread)
import Control.Concurrent.BoundedChan
import Control.Concurrent.Thread
import Control.Exception (SomeException)
import Control.Monad.CatchIO
import Control.Monad.Trans
import Prelude hiding (catch)
import qualified Data.Enumerator.List as E
{-# LANGUAGE BangPatterns #-}
-----------------------------------------------------------------------------
-- |
-- Copyright: 2010 John Millikin
-- License: MIT
--
-- Maintainer: [email protected]
-- Portability: portable
--
@gregorycollins
gregorycollins / new iteratee bind.hs
Created February 16, 2011 21:52
new iteratee bind
instance Monad m => Monad (Iteratee a m) where
return x = yield x (Chunks [])
m >>= f = bind m f
{-# INLINE bind #-}
bind :: Monad m =>
Iteratee a m b
-> (b -> Iteratee a m c)
-> Iteratee a m c
@gregorycollins
gregorycollins / gist:826935
Created February 15, 2011 01:30
Hashtable benchmark results feb 14 2011
ByteString keys between 8-32 characters long (ascii, hex digits). Test run on a Macbook Pro (2.53GHz Intel Core i5) running GHC 6.12.3.
$ ./dist/build/ucoll-benchmark/ucoll-benchmark +RTS -N -A4M
Results for Insert Performance
------------------------------------------------------------------------------
Data structure Data.Map
Input Sz Mean (secs) Stddev (secs) 95% (secs) Max (secs)
@gregorycollins
gregorycollins / criterion-collection-sample-output.txt
Created February 1, 2011 23:50
Sample output from "criterion-collection"
warming up
estimating clock resolution...
mean is 11.41351 us (80001 iterations)
found 7313 outliers among 79999 samples (9.1%)
1159 (1.4%) high mild
6137 (7.7%) high severe
estimating cost of a clock call...
mean is 166.3485 ns (77 iterations)
found 8 outliers among 77 samples (10.4%)
3 (3.9%) high mild
catchError' :: Monad m =>
Iteratee a m b
-> (SomeException -> Iteratee a m b)
-> Iteratee a m b
catchError' iter h = do
step <- lift $ runIteratee iter
go step
where
go step =
Tue Aug 24 18:04 2010 Time and Allocation Profiling Report (Final)
pongserver +RTS -p -A4M -qg0 -qb -g1 -RTS
total time = 24.18 secs (1209 ticks @ 20 ms)
total alloc = 13,228,877,164 bytes (excludes profiling overheads)
COST CENTRE MODULE %time %alloc
sendData Snap.Internal.Http.Server.LibevBackend 15.2 0.0