Skip to content

Commit

Permalink
Added benchmark program
Browse files Browse the repository at this point in the history
  • Loading branch information
cruppstahl committed Jun 12, 2015
1 parent ba02849 commit 4fb8555
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 16 deletions.
2 changes: 2 additions & 0 deletions .gitignore
@@ -1,4 +1,6 @@
test
benchmark
perf.data

# Object files
*.o
Expand Down
7 changes: 5 additions & 2 deletions Makefile
@@ -1,5 +1,5 @@

all: lib test
all: lib test benchmark
true

gen:
Expand All @@ -16,5 +16,8 @@ lib: for.o
test: test.c
$(CC) -g -O0 -Wall -Wextra -pedantic test.c -o test -L. -lfor

benchmark: benchmark.c
$(CC) -g -O3 -Wall -Wextra -pedantic benchmark.c -o benchmark -L. -lfor

for.o: for.h for.c for-gen.c
$(CC) -g -O0 -Wall -Wextra -pedantic for.c -c -o for.o
$(CC) -g -O3 -Wall -Wextra -pedantic for.c -c -o for.o
Binary file added benchmark
Binary file not shown.
66 changes: 66 additions & 0 deletions benchmark.c
@@ -0,0 +1,66 @@
/*
* Copyright (C) 2005-2015 Christoph Rupp (chris@crupp.de).
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <stdio.h>
#include <stdlib.h>

#include "for.h"

#define VERIFY(c) while (!c) { \
printf("%s:%d: expression failed\n", \
__FILE__, __LINE__); \
exit(-1); \
}

#define VERIFY_ARRAY(a1, a2, len) \
do { \
uint32_t i; \
for (i = 0; i < len; i++) { \
if (a1[i] != a2[i]) { \
printf("data mismatch at %u\n", i); \
exit(-1); \
} \
} \
} while (0)

static void
run(uint32_t length)
{
uint32_t i, s1, s2, s3;
uint8_t *out = (uint8_t *) malloc(length * sizeof(uint32_t));
uint32_t *in = (uint32_t *)malloc(length * sizeof(uint32_t));
uint32_t *tmp = (uint32_t *)malloc(length * sizeof(uint32_t));

for (i = 0; i < length; i++)
in[i] = 33 + i;

s1 = for_compress_sorted(in, out, length);
s2 = for_uncompress(out, tmp, length);
s3 = for_compressed_size_sorted(in, length);
VERIFY(s1 == s2);
VERIFY(s2 == s3);
/* VERIFY_ARRAY(in, tmp, length); */

free(in);
free(out);
free(tmp);
}

int
main()
{
run(1024 * 1024 * 10); /* 10 mb */
return 0;
}
16 changes: 2 additions & 14 deletions gen.pl
Expand Up @@ -108,13 +108,7 @@ sub generate_pack

my $fname = "pack$bits" . '_' . $block;

# for now always use 32bit blocks
if (0 && $bits * $block > 128) {
generate_pack_impl($fname, 'uint64_t', 64, $bits, $block);
}
else {
generate_pack_impl($fname, 'uint32_t', 32, $bits, $block);
}
generate_pack_impl($fname, 'uint32_t', 32, $bits, $block);
}

sub generate_unpack_impl
Expand Down Expand Up @@ -201,13 +195,7 @@ sub generate_unpack

my $fname = "unpack$bits" . '_' . $block;

# for now always use 32bit blocks
if (0 && $bits * $block > 128) {
generate_unpack_impl($fname, 'uint64_t', 64, $bits, $block);
}
else {
generate_unpack_impl($fname, 'uint32_t', 32, $bits, $block);
}
generate_unpack_impl($fname, 'uint32_t', 32, $bits, $block);
}

sub generate_packx
Expand Down

0 comments on commit 4fb8555

Please sign in to comment.