Permalink
Browse files

Get more numbers.

  • Loading branch information...
1 parent 09a8ff5 commit 98ce74c8b0ee0c734ad00c2e539e99d2a6fecefb @bos committed Jun 27, 2011
Showing with 14 additions and 6 deletions.
  1. +8 −6 benchmarks/Benchmarks.hs
  2. +6 −0 benchmarks/sprintf.c
View
@@ -17,14 +17,16 @@ main = defaultMain [
, bench "toFixed" $ whnf (toFixed 8) pi
]
, bgroup "sprintf" [
- bench "exponential" $ whnf (sprintf_exponential 3) pi
+ bench "exact" $ whnf sprintf_exact pi
+ , bench "exponential" $ whnf (sprintf_exponential 3) pi
, bench "fixed" $ whnf (sprintf_fixed 8) pi
, bench "generic" $ whnf (sprintf_generic 6) pi
- , bench "generic_default" $ whnf (sprintf_generic_default 6) pi
+ , bench "generic_default" $ whnf sprintf_generic_default pi
]
]
-foreign import ccall safe sprintf_exponential :: CInt -> CDouble -> ()
-foreign import ccall safe sprintf_fixed :: CInt -> CDouble -> ()
-foreign import ccall safe sprintf_generic :: CInt -> CDouble -> ()
-foreign import ccall safe sprintf_generic_default :: CInt -> CDouble -> ()
+foreign import ccall unsafe sprintf_exact :: CDouble -> ()
+foreign import ccall unsafe sprintf_exponential :: CInt -> CDouble -> ()
+foreign import ccall unsafe sprintf_fixed :: CInt -> CDouble -> ()
+foreign import ccall unsafe sprintf_generic :: CInt -> CDouble -> ()
+foreign import ccall unsafe sprintf_generic_default :: CDouble -> ()
View
@@ -1,5 +1,11 @@
#include <stdio.h>
+void sprintf_exact(double x)
+{
+ char buf[64];
+ snprintf(buf, 64, "%a", x);
+}
+
void sprintf_exponential(int d, double x)
{
char buf[64];

0 comments on commit 98ce74c

Please sign in to comment.