Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
go
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
go
Commits
78879b3b
Commit
78879b3b
authored
Mar 09, 2011
by
Nigel Tao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
compress/lzw: benchmark a range of input sizes.
R=rsc, nigeltao_gnome CC=golang-dev
https://golang.org/cl/4240096
parent
4896b175
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
45 additions
and
5 deletions
+45
-5
src/pkg/compress/lzw/reader_test.go
src/pkg/compress/lzw/reader_test.go
+21
-2
src/pkg/compress/lzw/writer_test.go
src/pkg/compress/lzw/writer_test.go
+24
-3
No files found.
src/pkg/compress/lzw/reader_test.go
View file @
78879b3b
...
@@ -9,6 +9,7 @@ import (
...
@@ -9,6 +9,7 @@ import (
"io"
"io"
"io/ioutil"
"io/ioutil"
"os"
"os"
"runtime"
"strconv"
"strconv"
"strings"
"strings"
"testing"
"testing"
...
@@ -117,16 +118,34 @@ func (devNull) Write(p []byte) (int, os.Error) {
...
@@ -117,16 +118,34 @@ func (devNull) Write(p []byte) (int, os.Error) {
return
len
(
p
),
nil
return
len
(
p
),
nil
}
}
func
BenchmarkDecoder
(
b
*
testing
.
B
)
{
func
benchmarkDecoder
(
b
*
testing
.
B
,
n
int
)
{
b
.
StopTimer
()
b
.
StopTimer
()
b
.
SetBytes
(
int64
(
n
))
buf0
,
_
:=
ioutil
.
ReadFile
(
"../testdata/e.txt"
)
buf0
,
_
:=
ioutil
.
ReadFile
(
"../testdata/e.txt"
)
buf0
=
buf0
[
:
10000
]
compressed
:=
bytes
.
NewBuffer
(
nil
)
compressed
:=
bytes
.
NewBuffer
(
nil
)
w
:=
NewWriter
(
compressed
,
LSB
,
8
)
w
:=
NewWriter
(
compressed
,
LSB
,
8
)
io
.
Copy
(
w
,
bytes
.
NewBuffer
(
buf0
))
for
i
:=
0
;
i
<
n
;
i
+=
len
(
buf0
)
{
io
.
Copy
(
w
,
bytes
.
NewBuffer
(
buf0
))
}
w
.
Close
()
w
.
Close
()
buf1
:=
compressed
.
Bytes
()
buf1
:=
compressed
.
Bytes
()
buf0
,
compressed
,
w
=
nil
,
nil
,
nil
runtime
.
GC
()
b
.
StartTimer
()
b
.
StartTimer
()
for
i
:=
0
;
i
<
b
.
N
;
i
++
{
for
i
:=
0
;
i
<
b
.
N
;
i
++
{
io
.
Copy
(
devNull
{},
NewReader
(
bytes
.
NewBuffer
(
buf1
),
LSB
,
8
))
io
.
Copy
(
devNull
{},
NewReader
(
bytes
.
NewBuffer
(
buf1
),
LSB
,
8
))
}
}
}
}
func
BenchmarkDecoder1e4
(
b
*
testing
.
B
)
{
benchmarkDecoder
(
b
,
1e4
)
}
func
BenchmarkDecoder1e5
(
b
*
testing
.
B
)
{
benchmarkDecoder
(
b
,
1e5
)
}
func
BenchmarkDecoder1e6
(
b
*
testing
.
B
)
{
benchmarkDecoder
(
b
,
1e6
)
}
src/pkg/compress/lzw/writer_test.go
View file @
78879b3b
...
@@ -8,6 +8,7 @@ import (
...
@@ -8,6 +8,7 @@ import (
"io"
"io"
"io/ioutil"
"io/ioutil"
"os"
"os"
"runtime"
"testing"
"testing"
)
)
...
@@ -99,13 +100,33 @@ func TestWriter(t *testing.T) {
...
@@ -99,13 +100,33 @@ func TestWriter(t *testing.T) {
}
}
}
}
func
BenchmarkEncoder
(
b
*
testing
.
B
)
{
func
benchmarkEncoder
(
b
*
testing
.
B
,
n
int
)
{
b
.
StopTimer
()
b
.
StopTimer
()
buf
,
_
:=
ioutil
.
ReadFile
(
"../testdata/e.txt"
)
b
.
SetBytes
(
int64
(
n
))
buf0
,
_
:=
ioutil
.
ReadFile
(
"../testdata/e.txt"
)
buf0
=
buf0
[
:
10000
]
buf1
:=
make
([]
byte
,
n
)
for
i
:=
0
;
i
<
n
;
i
+=
len
(
buf0
)
{
copy
(
buf1
[
i
:
],
buf0
)
}
buf0
=
nil
runtime
.
GC
()
b
.
StartTimer
()
b
.
StartTimer
()
for
i
:=
0
;
i
<
b
.
N
;
i
++
{
for
i
:=
0
;
i
<
b
.
N
;
i
++
{
w
:=
NewWriter
(
devNull
{},
LSB
,
8
)
w
:=
NewWriter
(
devNull
{},
LSB
,
8
)
w
.
Write
(
buf
)
w
.
Write
(
buf
1
)
w
.
Close
()
w
.
Close
()
}
}
}
}
func
BenchmarkEncoder1e4
(
b
*
testing
.
B
)
{
benchmarkEncoder
(
b
,
1e4
)
}
func
BenchmarkEncoder1e5
(
b
*
testing
.
B
)
{
benchmarkEncoder
(
b
,
1e5
)
}
func
BenchmarkEncoder1e6
(
b
*
testing
.
B
)
{
benchmarkEncoder
(
b
,
1e6
)
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment