Add Sander's day 1 benchmarks
parent
9139bf11fc
commit
500c885da6
|
|
@ -270,6 +270,7 @@ Cargo.lock
|
|||
*.pdb
|
||||
|
||||
# ---> Custom files
|
||||
bram/benchmarks/sander_hs/bin
|
||||
brechtje/**/*.txt
|
||||
|
||||
# If your structure requires you to ignore certain files or folders,
|
||||
|
|
|
|||
|
|
@ -0,0 +1,218 @@
|
|||
{
|
||||
"results": [
|
||||
{
|
||||
"command": "sander_hs/bin/d01-p1",
|
||||
"mean": 0.04911168208,
|
||||
"stddev": 0.01032973156660167,
|
||||
"median": 0.055515197020000004,
|
||||
"user": 0.03294559,
|
||||
"system": 0.009693189999999997,
|
||||
"min": 0.017305699020000002,
|
||||
"max": 0.06958076202,
|
||||
"times": [
|
||||
0.028148885020000007,
|
||||
0.02812234502,
|
||||
0.02839967402,
|
||||
0.04401772302,
|
||||
0.044329020020000005,
|
||||
0.044894278020000004,
|
||||
0.044741925020000003,
|
||||
0.055358096020000004,
|
||||
0.04492544502,
|
||||
0.044899033020000007,
|
||||
0.04474375802,
|
||||
0.045663883020000004,
|
||||
0.04363284102000001,
|
||||
0.04337241202000001,
|
||||
0.043829707020000004,
|
||||
0.04338248202000001,
|
||||
0.043564638020000004,
|
||||
0.043666556020000004,
|
||||
0.04448572002000001,
|
||||
0.04534801402000001,
|
||||
0.055672298020000004,
|
||||
0.05650688202,
|
||||
0.04466858902,
|
||||
0.044727196020000005,
|
||||
0.05606819202000001,
|
||||
0.05630577502000001,
|
||||
0.04196739202000001,
|
||||
0.056698006020000004,
|
||||
0.04718387702000001,
|
||||
0.04509804902,
|
||||
0.04421570902000001,
|
||||
0.028447144020000002,
|
||||
0.05268495302,
|
||||
0.056925696020000006,
|
||||
0.05670926802,
|
||||
0.05709284802000001,
|
||||
0.056762600020000005,
|
||||
0.05745422002000001,
|
||||
0.05684000402000001,
|
||||
0.046027741020000006,
|
||||
0.045032208020000006,
|
||||
0.05636665002000001,
|
||||
0.05729105602,
|
||||
0.056210446020000006,
|
||||
0.05684725402000001,
|
||||
0.05645790702000001,
|
||||
0.06151986702,
|
||||
0.05665584102000001,
|
||||
0.056705755020000005,
|
||||
0.05661739502000001,
|
||||
0.05766367202000001,
|
||||
0.05678177402,
|
||||
0.05803652102,
|
||||
0.05646028502000001,
|
||||
0.058079915020000004,
|
||||
0.05680949102000001,
|
||||
0.05642244302000001,
|
||||
0.045866505020000004,
|
||||
0.03218489402000001,
|
||||
0.05623631902,
|
||||
0.05718868602000001,
|
||||
0.04657174302000001,
|
||||
0.01875773202,
|
||||
0.017305699020000002,
|
||||
0.028071844020000007,
|
||||
0.05632571202000001,
|
||||
0.056854141020000006,
|
||||
0.05691621702,
|
||||
0.05666466802000001,
|
||||
0.05623132402000001,
|
||||
0.032242957020000004,
|
||||
0.04521475002000001,
|
||||
0.04536657302,
|
||||
0.05718462202000001,
|
||||
0.04684306102000001,
|
||||
0.029293676020000006,
|
||||
0.02914338702,
|
||||
0.039871728020000004,
|
||||
0.05688682402000001,
|
||||
0.05669724802,
|
||||
0.06717558102,
|
||||
0.05753922002000001,
|
||||
0.05684541902,
|
||||
0.05647092202,
|
||||
0.04162697102000001,
|
||||
0.044116325020000006,
|
||||
0.057613531020000004,
|
||||
0.05710429002000001,
|
||||
0.058932054020000006,
|
||||
0.05685631902000001,
|
||||
0.05945756902000001,
|
||||
0.06958076202,
|
||||
0.057347868020000005,
|
||||
0.05646610902000001,
|
||||
0.05678866702000001,
|
||||
0.04556446502000001,
|
||||
0.028980023020000002,
|
||||
0.04325268302,
|
||||
0.04377380002,
|
||||
0.04421396402
|
||||
],
|
||||
"exit_codes": [
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
# Build binaries
|
||||
ghc -O2 sander_hs/d01p1.hs -o sander_hs/bin/d01-p1
|
||||
|
||||
# Benchmark day 1
|
||||
hyperfine --warmup 5 --export-json data/sander-d01-p1.json --runs 100 \
|
||||
"sander_hs/bin/d01-p1"
|
||||
|
||||
|
|
@ -0,0 +1,40 @@
|
|||
import System.IO
|
||||
import Control.Monad
|
||||
|
||||
main :: IO()
|
||||
main = do handle <- openFile "../rust/inputs/01.txt" ReadMode
|
||||
contents <- hGetContents handle
|
||||
print (doday1_1 contents)
|
||||
hClose handle
|
||||
|
||||
-- Day 1: ...
|
||||
|
||||
-- Part One (correct)
|
||||
|
||||
doday1_1 :: String -> String
|
||||
doday1_1 input = show (countZeroRotations (words input) 50)
|
||||
|
||||
countZeroRotations :: [String] -> Int -> Int
|
||||
countZeroRotations [] _ = 0
|
||||
countZeroRotations (x : xs) pos = countZeroRotations xs (fst (rotateDial x pos)) + snd (rotateDial x pos)
|
||||
|
||||
rotateDial :: String -> Int -> (Int, Int)
|
||||
rotateDial (direction : r) pos
|
||||
| direction == 'L' && newposl == 0 = (normalizeHundred newposl, 1)
|
||||
| direction == 'L' = (normalizeHundred newposl, 0)
|
||||
| direction == 'R' && newposr == 0 = (normalizeHundred newposr, 1)
|
||||
| direction == 'R' = (normalizeHundred newposr, 0)
|
||||
where newposl = normalizeHundred (pos - (read r))
|
||||
newposr = normalizeHundred (pos + (read r))
|
||||
|
||||
normalizeHundred :: Int -> Int
|
||||
normalizeHundred x
|
||||
| x >= 0 && x < 100 = x
|
||||
| x >= 100 = normalizeHundred (x - 100)
|
||||
| x < 0 = normalizeHundred (x + 100)
|
||||
| True = x
|
||||
|
||||
-- Part Two
|
||||
|
||||
doday1_2 :: String -> String
|
||||
doday1_2 input = undefined
|
||||
|
|
@ -5,6 +5,9 @@ in pkgs.mkShell {
|
|||
# Benchmarking tool
|
||||
hyperfine
|
||||
|
||||
# Haskell
|
||||
haskell.compiler.native-bignum.ghc967
|
||||
|
||||
# Jupyter notebook
|
||||
(python312.withPackages
|
||||
(py-pkgs: with py-pkgs; [
|
||||
|
|
|
|||
Loading…
Reference in New Issue