Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Z
zlib-wasm
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
zlib-wasm
Commits
760bfda1
Commit
760bfda1
authored
Nov 11, 2019
by
nagayama15
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Write a simple benchmark
parent
38bd57e8
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
47 additions
and
1 deletion
+47
-1
import.h
src/import.h
+4
-0
zlib-exports.c
src/zlib-exports.c
+37
-1
test.js
test.js
+6
-0
No files found.
src/import.h
View file @
760bfda1
#pragma once
int
now
(
void
);
void
print
(
int
);
void
start_warm
(
void
);
void
start_bench
(
void
);
src/zlib-exports.c
View file @
760bfda1
...
...
@@ -6,7 +6,7 @@
#include "import.h"
#define RAW_DATA_SIZE ((uInt)2 * 1024 * 1024)
#define RAW_DATA_SIZE ((uInt)2
0
* 1024 * 1024)
static
unsigned
char
*
make_random_bytes
(
uInt
size
)
{
unsigned
char
*
buffer
=
malloc
(
size
);
...
...
@@ -18,6 +18,42 @@ static unsigned char *make_random_bytes(uInt size) {
return
buffer
;
}
export
void
run_benchmark
(
void
)
{
// Make a random byte sequence
srand
(
0
);
unsigned
char
*
raw_bytes
=
make_random_bytes
(
RAW_DATA_SIZE
);
int
level
=
9
;
int
n
=
10
;
uLongf
deflated_size
=
compressBound
(
RAW_DATA_SIZE
);
unsigned
char
*
deflated_bytes
=
malloc
(
deflated_size
);
// Warming up
start_warm
();
for
(
int
i
=
0
;
i
<
5
;
i
++
)
{
int
start_time
=
now
();
compress2
(
deflated_bytes
,
&
deflated_size
,
raw_bytes
,
RAW_DATA_SIZE
,
level
);
int
end_time
=
now
();
int
duration
=
end_time
-
start_time
;
print
(
duration
);
}
// Benchmark
start_bench
();
for
(
int
i
=
0
;
i
<
n
;
i
++
)
{
int
start_time
=
now
();
compress2
(
deflated_bytes
,
&
deflated_size
,
raw_bytes
,
RAW_DATA_SIZE
,
level
);
int
end_time
=
now
();
int
duration
=
end_time
-
start_time
;
print
(
duration
);
}
}
export
int
run_test
(
void
)
{
// Make a random byte sequence
srand
(
0
);
...
...
test.js
View file @
760bfda1
...
...
@@ -4,9 +4,15 @@ const wasm = require('webassembly');
(
async
()
=>
{
const
zlib
=
await
wasm
.
load
(
`
${
__dirname
}
/build/zlib.wasm`
,
{
imports
:
{
now
:
Date
.
now
,
print
:
console
.
log
,
start_warm
()
{
console
.
log
(
'warming up'
);
},
start_bench
()
{
console
.
log
(
'benchmark'
);
},
},
});
assert
.
strictEqual
(
zlib
.
exports
.
run_test
(),
0
);
zlib
.
exports
.
run_benchmark
();
})();
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