~ubuntu-branches/ubuntu/precise/haskell-text/precise

« back to all changes in this revision

Viewing changes to tests/benchmarks/DecodeUtf8.hs

  • Committer: Bazaar Package Importer
  • Author(s): Joachim Breitner
  • Date: 2011-04-13 11:38:29 UTC
  • mfrom: (4.1.3 sid)
  • Revision ID: james.westby@ubuntu.com-20110413113829-f4ss61ivg720e5bu
Tags: 0.11.0.6-1
New upstream release

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
import qualified Data.ByteString as B
 
2
import qualified Data.ByteString.Lazy as BL
 
3
import qualified Data.Text as T
 
4
import qualified Data.Text.IO as T
 
5
import qualified Data.Text.Encoding as T
 
6
import qualified Data.Text.Lazy as TL
 
7
import qualified Data.Text.Lazy.Encoding as TL
 
8
import qualified Data.Text.Lazy.IO as TL
 
9
import qualified Codec.Binary.UTF8.Generic as U8
 
10
import Control.DeepSeq
 
11
import System.Environment
 
12
import System.IO
 
13
 
 
14
strict h = do
 
15
  bs <- B.hGetContents h
 
16
  rnf (T.decodeUtf8 bs) `seq` return ()
 
17
 
 
18
strict_len h = do
 
19
  bs <- B.hGetContents h
 
20
  print . T.length . T.decodeUtf8 $ bs
 
21
 
 
22
strict_init_len h = do
 
23
  bs <- B.hGetContents h
 
24
  print . T.length . T.init . T.decodeUtf8 $ bs
 
25
 
 
26
strict_io h = do
 
27
  hSetEncoding h utf8
 
28
  t <- T.hGetContents h
 
29
  rnf t `seq` return ()
 
30
 
 
31
strict_len_io h = do
 
32
  hSetEncoding h utf8
 
33
  t <- T.hGetContents h
 
34
  print (T.length t)
 
35
 
 
36
lazy h = do
 
37
  bs <- BL.hGetContents h
 
38
  rnf (TL.decodeUtf8 bs) `seq` return ()
 
39
 
 
40
lazy_len h = do
 
41
  bs <- BL.hGetContents h
 
42
  print . TL.length . TL.decodeUtf8 $ bs
 
43
 
 
44
lazy_init_len h = do
 
45
  bs <- BL.hGetContents h
 
46
  print . TL.length . TL.init . TL.decodeUtf8 $ bs
 
47
 
 
48
lazy_io h = do
 
49
  hSetEncoding h utf8
 
50
  t <- TL.hGetContents h
 
51
  rnf t `seq` return ()
 
52
 
 
53
lazy_len_io h = do
 
54
  hSetEncoding h utf8
 
55
  t <- TL.hGetContents h
 
56
  print (TL.length t)
 
57
 
 
58
string h = do
 
59
  hSetEncoding h utf8
 
60
  t <- hGetContents h
 
61
  rnf t `seq` return ()
 
62
 
 
63
string_len h = do
 
64
  hSetEncoding h utf8
 
65
  t <- hGetContents h
 
66
  print (length t)
 
67
 
 
68
lazy_string_utf8 h = do
 
69
  bs <- BL.hGetContents h
 
70
  let t = U8.toString bs
 
71
  rnf t `seq` return ()
 
72
 
 
73
lazy_string_utf8_len h = do
 
74
  bs <- BL.hGetContents h
 
75
  let t = U8.toString bs
 
76
  print (length t)
 
77
 
 
78
strict_string_utf8 h = do
 
79
  bs <- B.hGetContents h
 
80
  let t = U8.toString bs
 
81
  rnf t `seq` return ()
 
82
 
 
83
strict_string_utf8_len h = do
 
84
  bs <- B.hGetContents h
 
85
  let t = U8.toString bs
 
86
  print (length t)
 
87
 
 
88
main = do
 
89
  [kind,name] <- getArgs
 
90
  h <- openFile name ReadMode
 
91
  case kind of
 
92
    "strict" -> strict h
 
93
    "strict_len" -> strict_len h
 
94
    "strict_init_len" -> strict_init_len h
 
95
    "strict_io" -> strict_io h
 
96
    "strict_len_io" -> strict_len_io h
 
97
    "lazy" -> lazy h
 
98
    "lazy_len" -> lazy_len h
 
99
    "lazy_init_len" -> lazy_init_len h
 
100
    "lazy_io" -> lazy_io h
 
101
    "lazy_len_io" -> lazy_len_io h
 
102
    "string" -> string h
 
103
    "string_len" -> string_len h
 
104
    "lazy_string_utf8" -> lazy_string_utf8 h
 
105
    "lazy_string_utf8_len" -> lazy_string_utf8_len h
 
106
    "strict_string_utf8" -> strict_string_utf8 h
 
107
    "strict_string_utf8_len" -> strict_string_utf8_len h