Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
L
llvm-watermarker
Project
Project
Details
Activity
Releases
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
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nagayama15
llvm-watermarker
Commits
d33e3455
Commit
d33e3455
authored
Dec 04, 2018
by
nagayama15
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
zlibの時間計測プログラムを追加
parent
b189523c
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
139 additions
and
2 deletions
+139
-2
Makefile
example/zlib/Makefile
+31
-2
test.cpp
example/zlib/test.cpp
+108
-0
No files found.
example/zlib/Makefile
View file @
d33e3455
...
@@ -3,12 +3,22 @@ include ../../common.mk
...
@@ -3,12 +3,22 @@ include ../../common.mk
WATERMARK
:=
77
WATERMARK
:=
77
CC
:=
clang
CC
:=
clang
CXX
:=
clang++
CFLAGS
:=
\
CFLAGS
:=
\
-D_LARGEFILE64_SOURCE
=
1
\
-D_LARGEFILE64_SOURCE
=
1
\
-DHAVE_HIDDEN
\
-DHAVE_HIDDEN
\
-O2
-O2
CXXFLAGS
:=
\
-std
=
c++17
\
-Wall
\
-Wextra
\
-pedantic
\
-Werror
\
-Izlib
\
-O2
SRCS
:=
\
SRCS
:=
\
zlib/adler32.c
\
zlib/adler32.c
\
zlib/compress.c
\
zlib/compress.c
\
...
@@ -31,12 +41,22 @@ OBJS_WM := ${SRCS:zlib/%.c=${OBJ_DIR}/zlib-${WATERMARK}/%.o}
...
@@ -31,12 +41,22 @@ OBJS_WM := ${SRCS:zlib/%.c=${OBJ_DIR}/zlib-${WATERMARK}/%.o}
.PHONY
:
all test
.PHONY
:
all test
all
:
${BIN_DIR}/libz.a ${BIN_DIR}/libz-${WATERMARK}.a
all
:
\
${BIN_DIR}/libz.a
\
${BIN_DIR}/libz-${WATERMARK}.a
\
${BIN_DIR}/test
\
${BIN_DIR}/test-${WATERMARK}
test
:
${BIN_DIR}/libz.a ${BIN_DIR}/libz-${WATERMARK}.a
test
:
\
${BIN_DIR}/libz.a
\
${BIN_DIR}/libz-${WATERMARK}.a
\
${BIN_DIR}/test
\
${BIN_DIR}/test-${WATERMARK}
${BIN_DIR}/libz.a
:
${OBJS}
${BIN_DIR}/libz.a
:
${OBJS}
${BIN_DIR}/libz-${WATERMARK}.a
:
${OBJS_WM}
${BIN_DIR}/libz-${WATERMARK}.a
:
${OBJS_WM}
${BIN_DIR}/test
:
${OBJ_DIR}/test.o ${BIN_DIR}/libz.a
${BIN_DIR}/test-${WATERMARK}
:
${OBJ_DIR}/test.o ${BIN_DIR}/libz-${WATERMARK}.a
${OBJ_DIR}/zlib/%.o
:
zlib/%.c
${OBJ_DIR}/zlib/%.o
:
zlib/%.c
@
mkdir
-p
${
@D
}
@
mkdir
-p
${
@D
}
...
@@ -48,6 +68,15 @@ ${OBJ_DIR}/zlib-${WATERMARK}/%.o: zlib/%.c
...
@@ -48,6 +68,15 @@ ${OBJ_DIR}/zlib-${WATERMARK}/%.o: zlib/%.c
opt
-load
=
${
ROOT
}
/bin/src/nykk.so
-block-wm
-watermark
=
${
WATERMARK
}
-S
-o
${
@
:%.o
=%-
${
WATERMARK
}
.ll
}
${
@
:.o
=.ll
}
2>
${
@
:%.o
=%-log.txt
}
opt
-load
=
${
ROOT
}
/bin/src/nykk.so
-block-wm
-watermark
=
${
WATERMARK
}
-S
-o
${
@
:%.o
=%-
${
WATERMARK
}
.ll
}
${
@
:.o
=.ll
}
2>
${
@
:%.o
=%-log.txt
}
clang
${
CFLAGS
}
-o
$@
-c
${
@
:%.o
=%-
${
WATERMARK
}
.ll
}
clang
${
CFLAGS
}
-o
$@
-c
${
@
:%.o
=%-
${
WATERMARK
}
.ll
}
${OBJ_DIR}/test.o
:
test.cpp
${
CXX
}
${
CXXFLAGS
}
-o
$@
-c
$<
${BIN_DIR}/test
:
${
CXX
}
${
CXXFLAGS
}
-o
$@
$^
${
LDFLAGS
}
${BIN_DIR}/test-${WATERMARK}
:
${
CXX
}
${
CXXFLAGS
}
-o
$@
$^
${
LDFLAGS
}
%.a
:
%.a
:
@
mkdir
-p
${
@D
}
@
mkdir
-p
${
@D
}
${
AR
}
rcs
$@
$^
${
AR
}
rcs
$@
$^
example/zlib/test.cpp
0 → 100644
View file @
d33e3455
#include <array>
#include <chrono>
#include <cstddef>
#include <iostream>
#include <random>
#include <vector>
#include <zlib.h>
namespace
{
void
compression_test
(
const
std
::
vector
<
std
::
byte
>&
raw_test_data
,
std
::
vector
<
std
::
byte
>&
buffer
,
int
level
)
{
::
z_stream
zs
=
{};
zs
.
next_in
=
reinterpret_cast
<
Bytef
*>
(
const_cast
<
std
::
byte
*>
(
raw_test_data
.
data
()));
// Never rewrited.
zs
.
avail_in
=
raw_test_data
.
size
();
zs
.
next_out
=
reinterpret_cast
<
Bytef
*>
(
buffer
.
data
());
zs
.
avail_out
=
buffer
.
size
();
::
deflateInit2
(
&
zs
,
level
,
Z_DEFLATED
,
-
MAX_WBITS
,
8
,
Z_DEFAULT_STRATEGY
);
::
deflate
(
&
zs
,
Z_FINISH
);
::
deflateEnd
(
&
zs
);
}
void
decompression_test
(
const
std
::
vector
<
std
::
byte
>&
compressed_test_data
,
std
::
vector
<
std
::
byte
>&
buffer
)
{
::
z_stream
zs
=
{};
zs
.
next_in
=
reinterpret_cast
<
Bytef
*>
(
const_cast
<
std
::
byte
*>
(
compressed_test_data
.
data
()));
// Never rewrited.
zs
.
avail_in
=
compressed_test_data
.
size
();
zs
.
next_out
=
reinterpret_cast
<
Bytef
*>
(
buffer
.
data
());
zs
.
avail_out
=
buffer
.
size
();
::
inflateInit2
(
&
zs
,
-
MAX_WBITS
);
::
inflate
(
&
zs
,
Z_FINISH
);
::
inflateEnd
(
&
zs
);
}
template
<
typename
F
>
std
::
chrono
::
high_resolution_clock
::
duration
measure
(
F
&&
f
)
{
const
auto
start
=
std
::
chrono
::
high_resolution_clock
::
now
();
f
();
const
auto
end
=
std
::
chrono
::
high_resolution_clock
::
now
();
return
end
-
start
;
}
}
int
main
()
{
// 200MB random array.
const
auto
raw_test_data
=
[]()
{
constexpr
std
::
size_t
size
=
200
*
1024
*
1024
;
auto
data
=
std
::
vector
<
std
::
byte
>
(
size
);
auto
rand
=
std
::
mt19937
{};
// Always use the default seed to get the same result.
using
ByteBase
=
std
::
underlying_type_t
<
std
::
byte
>
;
// unsigned char
auto
dist
=
std
::
uniform_int_distribution
<
ByteBase
>
{
ByteBase
(
0
),
ByteBase
(
-
1
)
};
for
(
auto
&
x
:
data
)
{
x
=
std
::
byte
{
dist
(
rand
)
};
}
return
data
;
}();
// Compressed `test_data`.
const
auto
compressed_test_data
=
[
&
]()
{
auto
data
=
std
::
vector
<
std
::
byte
>
(
::
compressBound
(
raw_test_data
.
size
()));
::
z_stream
zs
=
{};
zs
.
next_in
=
reinterpret_cast
<
Bytef
*>
(
const_cast
<
std
::
byte
*>
(
raw_test_data
.
data
()));
// Never rewrited.
zs
.
avail_in
=
raw_test_data
.
size
();
zs
.
next_out
=
reinterpret_cast
<
Bytef
*>
(
data
.
data
());
zs
.
avail_out
=
data
.
size
();
::
deflateInit2
(
&
zs
,
9
,
Z_DEFLATED
,
-
MAX_WBITS
,
8
,
Z_DEFAULT_STRATEGY
);
::
deflate
(
&
zs
,
Z_FINISH
);
::
deflateEnd
(
&
zs
);
return
std
::
vector
<
std
::
byte
>
(
std
::
begin
(
data
),
std
::
end
(
data
));
}();
std
::
cout
<<
"compression[us],decompression[us]"
<<
std
::
endl
;
constexpr
std
::
size_t
n
=
100
;
auto
output_buffer
=
std
::
vector
<
std
::
byte
>
(
::
compressBound
(
raw_test_data
.
size
()));
for
(
std
::
size_t
i
=
0
;
i
<
n
;
i
++
)
{
const
auto
compression_time
=
measure
([
&
]()
{
compression_test
(
raw_test_data
,
output_buffer
,
9
);
});
const
auto
decompression_time
=
measure
([
&
]()
{
decompression_test
(
compressed_test_data
,
output_buffer
);
});
std
::
cout
<<
std
::
chrono
::
duration_cast
<
std
::
chrono
::
microseconds
>
(
compression_time
).
count
()
<<
","
<<
std
::
chrono
::
duration_cast
<
std
::
chrono
::
microseconds
>
(
decompression_time
).
count
()
<<
std
::
endl
;
}
}
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