Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
G
golang
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
go
golang
Commits
6ec6f1ef
Commit
6ec6f1ef
authored
Jul 12, 2011
by
Nigel Tao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
image/draw: add benchmarks.
R=r CC=golang-dev
https://golang.org/cl/4695043
parent
1002e82f
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
206 additions
and
0 deletions
+206
-0
bench_test.go
src/pkg/image/draw/bench_test.go
+206
-0
No files found.
src/pkg/image/draw/bench_test.go
0 → 100644
View file @
6ec6f1ef
// Copyright 2011 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package
draw
import
(
"image"
"image/ycbcr"
"testing"
)
const
(
dstw
,
dsth
=
640
,
480
srcw
,
srch
=
400
,
300
)
// bench benchmarks drawing src and mask images onto a dst image with the
// given op and the color models to create those images from.
// The created images' pixels are initialized to non-zero values.
func
bench
(
b
*
testing
.
B
,
dcm
,
scm
,
mcm
image
.
ColorModel
,
op
Op
)
{
b
.
StopTimer
()
var
dst
Image
switch
dcm
{
case
image
.
RGBAColorModel
:
dst1
:=
image
.
NewRGBA
(
dstw
,
dsth
)
for
y
:=
0
;
y
<
dsth
;
y
++
{
for
x
:=
0
;
x
<
dstw
;
x
++
{
dst1
.
SetRGBA
(
x
,
y
,
image
.
RGBAColor
{
uint8
(
5
*
x
%
0x100
),
uint8
(
7
*
y
%
0x100
),
uint8
((
7
*
x
+
5
*
y
)
%
0x100
),
0xff
,
})
}
}
dst
=
dst1
case
image
.
RGBA64ColorModel
:
dst1
:=
image
.
NewRGBA64
(
dstw
,
dsth
)
for
y
:=
0
;
y
<
dsth
;
y
++
{
for
x
:=
0
;
x
<
dstw
;
x
++
{
dst1
.
SetRGBA64
(
x
,
y
,
image
.
RGBA64Color
{
uint16
(
53
*
x
%
0x10000
),
uint16
(
59
*
y
%
0x10000
),
uint16
((
59
*
x
+
53
*
y
)
%
0x10000
),
0xffff
,
})
}
}
dst
=
dst1
default
:
panic
(
"unreachable"
)
}
var
src
image
.
Image
switch
scm
{
case
nil
:
src
=
&
image
.
ColorImage
{
image
.
RGBAColor
{
0x11
,
0x22
,
0x33
,
0xff
}}
case
image
.
RGBAColorModel
:
src1
:=
image
.
NewRGBA
(
srcw
,
srch
)
for
y
:=
0
;
y
<
srch
;
y
++
{
for
x
:=
0
;
x
<
srcw
;
x
++
{
src1
.
SetRGBA
(
x
,
y
,
image
.
RGBAColor
{
uint8
(
13
*
x
%
0x80
),
uint8
(
11
*
y
%
0x80
),
uint8
((
11
*
x
+
13
*
y
)
%
0x80
),
0x7f
,
})
}
}
src
=
src1
case
image
.
RGBA64ColorModel
:
src1
:=
image
.
NewRGBA64
(
srcw
,
srch
)
for
y
:=
0
;
y
<
srch
;
y
++
{
for
x
:=
0
;
x
<
srcw
;
x
++
{
src1
.
SetRGBA64
(
x
,
y
,
image
.
RGBA64Color
{
uint16
(
103
*
x
%
0x8000
),
uint16
(
101
*
y
%
0x8000
),
uint16
((
101
*
x
+
103
*
y
)
%
0x8000
),
0x7fff
,
})
}
}
src
=
src1
case
image
.
NRGBAColorModel
:
src1
:=
image
.
NewNRGBA
(
srcw
,
srch
)
for
y
:=
0
;
y
<
srch
;
y
++
{
for
x
:=
0
;
x
<
srcw
;
x
++
{
src1
.
SetNRGBA
(
x
,
y
,
image
.
NRGBAColor
{
uint8
(
13
*
x
%
0x100
),
uint8
(
11
*
y
%
0x100
),
uint8
((
11
*
x
+
13
*
y
)
%
0x100
),
0x7f
,
})
}
}
src
=
src1
case
ycbcr
.
YCbCrColorModel
:
yy
:=
make
([]
uint8
,
srcw
*
srch
)
cb
:=
make
([]
uint8
,
srcw
*
srch
)
cr
:=
make
([]
uint8
,
srcw
*
srch
)
for
i
:=
range
yy
{
yy
[
i
]
=
uint8
(
3
*
i
%
0x100
)
cb
[
i
]
=
uint8
(
5
*
i
%
0x100
)
cr
[
i
]
=
uint8
(
7
*
i
%
0x100
)
}
src
=
&
ycbcr
.
YCbCr
{
Y
:
yy
,
Cb
:
cb
,
Cr
:
cr
,
YStride
:
srcw
,
CStride
:
srcw
,
SubsampleRatio
:
ycbcr
.
SubsampleRatio444
,
Rect
:
image
.
Rect
(
0
,
0
,
srcw
,
srch
),
}
default
:
panic
(
"unreachable"
)
}
var
mask
image
.
Image
switch
mcm
{
case
nil
:
// No-op.
case
image
.
AlphaColorModel
:
mask1
:=
image
.
NewAlpha
(
srcw
,
srch
)
for
y
:=
0
;
y
<
srch
;
y
++
{
for
x
:=
0
;
x
<
srcw
;
x
++
{
a
:=
uint8
((
23
*
x
+
29
*
y
)
%
0x100
)
// Glyph masks are typically mostly zero,
// so we only set a quarter of mask1's pixels.
if
a
>=
0xc0
{
mask1
.
SetAlpha
(
x
,
y
,
image
.
AlphaColor
{
a
})
}
}
}
mask
=
mask1
default
:
panic
(
"unreachable"
)
}
b
.
StartTimer
()
for
i
:=
0
;
i
<
b
.
N
;
i
++
{
// Scatter the destination rectangle to draw into.
x
:=
3
*
i
%
(
dstw
-
srcw
)
y
:=
7
*
i
%
(
dsth
-
srch
)
DrawMask
(
dst
,
dst
.
Bounds
()
.
Add
(
image
.
Point
{
x
,
y
}),
src
,
image
.
ZP
,
mask
,
image
.
ZP
,
op
)
}
}
// The BenchmarkFoo functions exercise a drawFoo fast-path function in draw.go.
func
BenchmarkFillOver
(
b
*
testing
.
B
)
{
bench
(
b
,
image
.
RGBAColorModel
,
nil
,
nil
,
Over
)
}
func
BenchmarkFillSrc
(
b
*
testing
.
B
)
{
bench
(
b
,
image
.
RGBAColorModel
,
nil
,
nil
,
Src
)
}
func
BenchmarkCopyOver
(
b
*
testing
.
B
)
{
bench
(
b
,
image
.
RGBAColorModel
,
image
.
RGBAColorModel
,
nil
,
Over
)
}
func
BenchmarkCopySrc
(
b
*
testing
.
B
)
{
bench
(
b
,
image
.
RGBAColorModel
,
image
.
RGBAColorModel
,
nil
,
Src
)
}
func
BenchmarkNRGBAOver
(
b
*
testing
.
B
)
{
bench
(
b
,
image
.
RGBAColorModel
,
image
.
NRGBAColorModel
,
nil
,
Over
)
}
func
BenchmarkNRGBASrc
(
b
*
testing
.
B
)
{
bench
(
b
,
image
.
RGBAColorModel
,
image
.
NRGBAColorModel
,
nil
,
Src
)
}
func
BenchmarkYCbCr
(
b
*
testing
.
B
)
{
bench
(
b
,
image
.
RGBAColorModel
,
ycbcr
.
YCbCrColorModel
,
nil
,
Over
)
}
func
BenchmarkGlyphOver
(
b
*
testing
.
B
)
{
bench
(
b
,
image
.
RGBAColorModel
,
nil
,
image
.
AlphaColorModel
,
Over
)
}
func
BenchmarkRGBA
(
b
*
testing
.
B
)
{
bench
(
b
,
image
.
RGBAColorModel
,
image
.
RGBA64ColorModel
,
nil
,
Src
)
}
// The BenchmarkGenericFoo functions exercise the generic, slow-path code.
func
BenchmarkGenericOver
(
b
*
testing
.
B
)
{
bench
(
b
,
image
.
RGBA64ColorModel
,
image
.
RGBA64ColorModel
,
nil
,
Over
)
}
func
BenchmarkGenericMaskOver
(
b
*
testing
.
B
)
{
bench
(
b
,
image
.
RGBA64ColorModel
,
image
.
RGBA64ColorModel
,
image
.
AlphaColorModel
,
Over
)
}
func
BenchmarkGenericSrc
(
b
*
testing
.
B
)
{
bench
(
b
,
image
.
RGBA64ColorModel
,
image
.
RGBA64ColorModel
,
nil
,
Src
)
}
func
BenchmarkGenericMaskSrc
(
b
*
testing
.
B
)
{
bench
(
b
,
image
.
RGBA64ColorModel
,
image
.
RGBA64ColorModel
,
image
.
AlphaColorModel
,
Src
)
}
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