Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a few simple apples-to-apples formatting benchmarks.
--HG-- rename : tests/Benchmarks.hs => benchmarks/Benchmarks.hs rename : tests/Makefile => benchmarks/Makefile
- Loading branch information
Showing
7 changed files
with
128 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
ghc := ghc | ||
|
||
programs := bm simple sprintf swprintf | ||
|
||
all: $(programs) | ||
|
||
bm: Benchmarks.hs | ||
$(ghc) -rtsopts -O -o $@ $< | ||
|
||
simple: Simple.hs | ||
$(ghc) -rtsopts -O -o $@ $< | ||
|
||
sprintf: sprintf.c | ||
$(CC) -O2 -o $@ $< | ||
|
||
swprintf: swprintf.c | ||
$(CC) -O2 -o $@ $< | ||
|
||
clean: | ||
-rm -f $(programs) *.hi *.o *.hp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{-# LANGUAGE BangPatterns, OverloadedStrings #-} | ||
|
||
import Control.Monad | ||
import System.Environment | ||
import qualified Data.Text.Format as T | ||
import Data.Time.Clock | ||
|
||
main = do | ||
args <- getArgs | ||
let count = case args of | ||
(x:_) -> read x :: Int | ||
_ -> 100000 | ||
start <- getCurrentTime | ||
forM_ [0..count] $ \i -> do | ||
let !t = T.format "hi mom {}\n" [fromIntegral i * pi::Double] | ||
return () | ||
elapsed <- (`diffUTCTime` start) `fmap` getCurrentTime | ||
T.print "{} iterations in {} secs ({} thousand/sec\n" | ||
(count, elapsed, | ||
fromRational (toRational count / toRational elapsed / 1e3) :: Double) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
#include <math.h> | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <sys/time.h> | ||
|
||
double gettime(void) | ||
{ | ||
struct timeval tv; | ||
|
||
gettimeofday(&tv, NULL); | ||
|
||
return tv.tv_sec + (tv.tv_usec / 1e6); | ||
} | ||
|
||
void loop(int count) | ||
{ | ||
int i; | ||
|
||
for (i = 0; i < count; i++) { | ||
char *s = malloc(64); | ||
|
||
sprintf(s, "hi mom %g\n", (double) i * M_PI); | ||
|
||
free(s); | ||
} | ||
} | ||
|
||
int main(int argc, char **argv) | ||
{ | ||
double start, elapsed; | ||
int i, count; | ||
|
||
count = argc == 2 ? atoi(argv[1]) : 1600000; | ||
|
||
start = gettime(); | ||
|
||
loop(count); | ||
|
||
elapsed = gettime() - start; | ||
|
||
printf("%d iterations in %g secs (%g thousand/sec)\n", count, elapsed, | ||
count / elapsed / 1e3); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
#include <math.h> | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <sys/time.h> | ||
#include <wchar.h> | ||
|
||
double gettime(void) | ||
{ | ||
struct timeval tv; | ||
|
||
gettimeofday(&tv, NULL); | ||
|
||
return tv.tv_sec + (tv.tv_usec / 1e6); | ||
} | ||
|
||
void loop(int count) | ||
{ | ||
int i; | ||
|
||
for (i = 0; i < count; i++) { | ||
wchar_t *s = malloc(64 * sizeof(wchar_t)); | ||
|
||
swprintf(s, 64, L"hi mom %g\n", (double) i * M_PI); | ||
|
||
free(s); | ||
} | ||
} | ||
|
||
int main(int argc, char **argv) | ||
{ | ||
double start, elapsed; | ||
int i, count; | ||
|
||
count = argc == 2 ? atoi(argv[1]) : 1600000; | ||
|
||
start = gettime(); | ||
|
||
loop(count); | ||
|
||
elapsed = gettime() - start; | ||
|
||
printf("%d iterations in %g secs (%g thousand/sec)\n", count, elapsed, | ||
count / elapsed / 1e3); | ||
} |
This file was deleted.
Oops, something went wrong.