Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
T
text
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Analyze
Contributor analytics
CI/CD analytics
Repository analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Glasgow Haskell Compiler
Packages
text
Commits
60ab2baf
Commit
60ab2baf
authored
14 years ago
by
Jasper Van der Jeugt
Browse files
Options
Downloads
Patches
Plain Diff
Purify Replace benchmark
parent
cc24e80b
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
tests/benchmarks/src/Data/Text/Benchmarks.hs
+1
-1
1 addition, 1 deletion
tests/benchmarks/src/Data/Text/Benchmarks.hs
tests/benchmarks/src/Data/Text/Benchmarks/Replace.hs
+10
-16
10 additions, 16 deletions
tests/benchmarks/src/Data/Text/Benchmarks/Replace.hs
with
11 additions
and
17 deletions
tests/benchmarks/src/Data/Text/Benchmarks.hs
+
1
−
1
View file @
60ab2baf
...
...
@@ -48,7 +48,7 @@ benchmarks = do
,
Ordering
.
benchmark
(
tf
"russian.txt"
)
,
Pure
.
benchmark
(
tf
"japanese.txt"
)
,
ReadNumbers
.
benchmark
(
tf
"numbers.txt"
)
,
Replace
.
benchmark
(
tf
"russian.txt"
)
sink
"принимая"
"своем"
,
Replace
.
benchmark
(
tf
"russian.txt"
)
"принимая"
"своем"
,
Search
.
benchmark
(
tf
"russian.txt"
)
"принимая"
,
WordCount
.
benchmark
(
tf
"russian.txt"
)
]
...
...
This diff is collapsed.
Click to expand it.
tests/benchmarks/src/Data/Text/Benchmarks/Replace.hs
+
10
−
16
View file @
60ab2baf
-- | Replace a string by another string
in a file
-- | Replace a string by another string
--
module
Data.Text.Benchmarks.Replace
(
benchmark
)
where
import
Criterion
(
Benchmark
,
bgroup
,
bench
)
import
System.IO
(
Handle
)
import
Criterion
(
Benchmark
,
bgroup
,
bench
,
nf
)
import
qualified
Data.ByteString.Char8
as
B
import
qualified
Data.ByteString.Lazy
as
BL
import
qualified
Data.ByteString.Lazy.Search
as
BL
...
...
@@ -13,19 +12,14 @@ import qualified Data.Text.Lazy as TL
import
qualified
Data.Text.Lazy.Encoding
as
TL
import
qualified
Data.Text.Lazy.IO
as
TL
benchmark
::
FilePath
->
Handle
->
String
->
String
->
IO
Benchmark
benchmark
fp
sink
pat
sub
=
return
$
bgroup
"Replace"
-- We have benchmarks for lazy text and lazy bytestrings. We also benchmark
-- without the acual replacement, so we can get an idea of what time is
-- spent on IO and computations.
[
bench
"LazyText"
$
TL
.
readFile
fp
>>=
TL
.
hPutStr
sink
.
TL
.
replace
tpat
tsub
,
bench
"LazyTextNull"
$
TL
.
readFile
fp
>>=
TL
.
hPutStr
sink
,
bench
"LazyByteString"
$
BL
.
readFile
fp
>>=
BL
.
hPutStr
sink
.
BL
.
replace
bpat
bsub
,
bench
"LazyByteStringNull"
$
BL
.
readFile
fp
>>=
BL
.
hPutStr
sink
]
benchmark
::
FilePath
->
String
->
String
->
IO
Benchmark
benchmark
fp
pat
sub
=
do
tl
<-
TL
.
readFile
fp
bl
<-
BL
.
readFile
fp
return
$
bgroup
"Replace"
[
bench
"LazyText"
$
nf
(
TL
.
length
.
TL
.
replace
tpat
tsub
)
tl
,
bench
"LazyByteString"
$
nf
(
BL
.
length
.
BL
.
replace
bpat
bsub
)
bl
]
where
tpat
=
TL
.
pack
pat
tsub
=
TL
.
pack
sub
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment