Skip to content

Commit

Permalink
Benchmark (#23)
Browse files Browse the repository at this point in the history
* Fix benchmark values
* Add custom benchmark tool for rsidvar
  • Loading branch information
nicolaasuni committed Jul 6, 2018
1 parent d0da7ab commit 6808ecb
Show file tree
Hide file tree
Showing 12 changed files with 218 additions and 17 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.7.0
2.7.1
1 change: 1 addition & 0 deletions c/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ set(CPACK_DEB_COMPONENT_INSTALL TRUE)
add_subdirectory(src)
add_subdirectory(test)
add_subdirectory(vk)
add_subdirectory(test/rsidvar_bench)

# Build Documentation
find_package(Doxygen QUIET)
Expand Down
11 changes: 11 additions & 0 deletions c/test/rsidvar_bench/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib)
set(RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/cmd)

# Add the binary tree directory to the search path for linking and include files
link_directories(${PROJECT_BINARY_DIR}/src)
include_directories(${CMAKE_CURRENT_BINARY_DIR} ${PROJECT_BINARY_DIR}/src)

file(COPY DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
add_executable(rsidvar_bench rsidvar_bench.c)
target_link_libraries(rsidvar_bench variantkey)
189 changes: 189 additions & 0 deletions c/test/rsidvar_bench/rsidvar_bench.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,189 @@
// Benchmark tool for rsidvar
//
// rsidvar_bench.c
//
// @category Tools
// @author Nicola Asuni <nicola.asuni@genomicsplc.com>
// @copyright 2017-2018 GENOMICS plc
// @license MIT (see LICENSE)
// @link https://github.com/genomicsplc/variantkey
//
// LICENSE
//
// Copyright (c) 2017-2018 GENOMICS plc
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
//
// VariantKey by Nicola Asuni

// NOTE: This test is slow because it generates the test files from scratch.

#if __STDC_VERSION__ >= 199901L
#define _XOPEN_SOURCE 600
#else
#define _XOPEN_SOURCE 500
#endif

#include <inttypes.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <sys/mman.h>
#include "../../src/rsidvar.h"

#define TEST_DATA_SIZE 400000000UL

// returns current time in nanoseconds
uint64_t get_time()
{
struct timespec t;
clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &t);
return (((uint64_t)t.tv_sec * 1000000000) + (uint64_t)t.tv_nsec);
}

int benchmark_find_rv_variantkey_by_rsid()
{
const char *filename = "rsvk_test_400M.bin";

uint32_t i;

FILE *f = fopen(filename, "w");
if (f == NULL)
{
fprintf(stderr, " * %s Unable to open %s file in writing mode.\n", __func__, filename);
return 1;
}
unsigned char b0, b1, b2, b3, z = 0;
for (i=0 ; i < TEST_DATA_SIZE; i++)
{
b0 = i & 0xFF;
b1 = (i >> 8) & 0xFF;
b2 = (i >> 16) & 0xFF;
b3 = (i >> 24) & 0xFF;
fprintf(f, "%c%c%c%c%c%c%c%c%c%c%c%c", b3, b2, b1, b0, z, z, z, z, b3, b2, b1, b0);
}
fclose(f);

mmfile_t rv = {0};
mmap_binfile(filename, &rv);
uint64_t nitems = (uint64_t)(rv.size / BINBLKLEN);
if (nitems != TEST_DATA_SIZE)
{
fprintf(stderr, " * %s Expecting rsvk_test_400M.bin %" PRIu64 " items, got instead: %" PRIu64 "\n", __func__, TEST_DATA_SIZE, nitems);
return 1;
}

uint64_t tstart, tend, offset;
volatile uint64_t sum = 0;
uint64_t first;

tstart = get_time();
for (i=0 ; i < TEST_DATA_SIZE; i++)
{
sum += i;
}
tend = get_time();
offset = (tend - tstart);
fprintf(stdout, " * %s sum: %" PRIu64 "\n", __func__, sum);

int j;
for (j=0 ; j < 3; j++)
{
sum = 0;
tstart = get_time();
for (i=0 ; i < TEST_DATA_SIZE; i++)
{
first = 0;
sum += find_rv_variantkey_by_rsid(rv.src, &first, TEST_DATA_SIZE, i);
}
tend = get_time();
fprintf(stdout, " * %s %d. sum: %" PRIu64 " -- time: %" PRIu64 " ns -- %" PRIu64 " ns/op\n", __func__, j, sum, (tend - tstart - offset), (tend - tstart - offset)/TEST_DATA_SIZE);
}
return 0;
}

int benchmark_find_vr_rsid_by_variantkey()
{
const char *filename = "vkrs_test_400M.bin";

uint64_t i;

FILE *f = fopen(filename, "w");
if (f == NULL)
{
fprintf(stderr, " * %s Unable to open %s file in writing mode.\n", __func__, filename);
return 1;
}
unsigned char b0, b1, b2, b3, z = 0;
for (i=0 ; i < TEST_DATA_SIZE; i++)
{
b0 = i & 0xFF;
b1 = (i >> 8) & 0xFF;
b2 = (i >> 16) & 0xFF;
b3 = (i >> 24) & 0xFF;
fprintf(f, "%c%c%c%c%c%c%c%c%c%c%c%c", z, z, z, z, b3, b2, b1, b0, b3, b2, b1, b0);
}
fclose(f);

mmfile_t vr = {0};
mmap_binfile(filename, &vr);
uint64_t nitems = (uint64_t)(vr.size / BINBLKLEN);
if (nitems != TEST_DATA_SIZE)
{
fprintf(stderr, " * %s Expecting vkrs_test_400M.bin %" PRIu64 " items, got instead: %" PRIu64 "\n", __func__, TEST_DATA_SIZE, nitems);
return 1;
}

uint64_t tstart, tend, offset;
volatile uint64_t sum = 0;
uint64_t first;

tstart = get_time();
for (i=0 ; i < TEST_DATA_SIZE; i++)
{
sum += i;
}
tend = get_time();
offset = (tend - tstart);
fprintf(stdout, " * %s sum: %" PRIu64 "\n", __func__, sum);

int j;
for (j=0 ; j < 3; j++)
{
sum = 0;
tstart = get_time();
for (i=0 ; i < TEST_DATA_SIZE; i++)
{
first = 0;
sum += find_vr_rsid_by_variantkey(vr.src, &first, TEST_DATA_SIZE, i);
}
tend = get_time();
fprintf(stdout, " * %s %d. sum: %" PRIu64 " -- time: %" PRIu64 " ns -- %" PRIu64 " ns/op\n", __func__, j, sum, (tend - tstart - offset), (tend - tstart - offset)/TEST_DATA_SIZE);
}
return 0;
}

int main()
{
int ret = 0;
ret += benchmark_find_rv_variantkey_by_rsid();
ret += benchmark_find_vr_rsid_by_variantkey();
return ret;
}
8 changes: 4 additions & 4 deletions c/test/test_binsearch.c
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ void benchmark_find_first_##T(mmfile_t mf, uint64_t blklen, uint64_t nitems) \
find_first_##T(mf.src, blklen, test_data_##T[4].blkpos, &first, &last, test_data_##T[4].search); \
} \
tend = get_time(); \
fprintf(stdout, " * %s : %lu ns/op\n", __func__, (tend - tstart)/(size*4)); \
fprintf(stdout, " * %s : %lu ns/op\n", __func__, (tend - tstart)/size); \
}

define_benchmark_find_first(uint8_t)
Expand All @@ -417,7 +417,7 @@ void benchmark_find_last_##T(mmfile_t mf, uint64_t blklen, uint64_t nitems) \
find_last_##T(mf.src, blklen, test_data_##T[4].blkpos, &first, &last, test_data_##T[4].search); \
} \
tend = get_time(); \
fprintf(stdout, " * %s : %lu ns/op\n", __func__, (tend - tstart)/(size*4)); \
fprintf(stdout, " * %s : %lu ns/op\n", __func__, (tend - tstart)/size); \
}

define_benchmark_find_last(uint8_t)
Expand All @@ -439,7 +439,7 @@ void benchmark_find_first_sub_##T(mmfile_t mf, uint64_t blklen, uint8_t bitstart
find_first_sub_##T(mf.src, blklen, test_data_##T[4].blkpos, bitstart, bitend, &first, &last, test_data_##T[4].search); \
} \
tend = get_time(); \
fprintf(stdout, " * %s : %lu ns/op\n", __func__, (tend - tstart)/(size*4)); \
fprintf(stdout, " * %s : %lu ns/op\n", __func__, (tend - tstart)/size); \
}

define_benchmark_find_first_sub(uint8_t)
Expand All @@ -461,7 +461,7 @@ void benchmark_find_last_sub_##T(mmfile_t mf, uint64_t blklen, uint8_t bitstart,
find_last_sub_##T(mf.src, blklen, test_data_##T[4].blkpos, bitstart, bitend, &first, &last, test_data_##T[4].search); \
} \
tend = get_time(); \
fprintf(stdout, " * %s : %lu ns/op\n", __func__, (tend - tstart)/(size*4)); \
fprintf(stdout, " * %s : %lu ns/op\n", __func__, (tend - tstart)/size); \
}

define_benchmark_find_last_sub(uint8_t)
Expand Down
4 changes: 2 additions & 2 deletions c/test/test_nrvk.c
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ void benchmark_find_ref_alt_by_variantkey(mmfile_t vknr)
find_ref_alt_by_variantkey(vknr.src, vknr.last, 0xb000c35b64690b25, ref, &sizeref, alt, &sizealt);
}
tend = get_time();
fprintf(stdout, " * %s : %lu ns/op\n", __func__, (tend - tstart)/(size*4));
fprintf(stdout, " * %s : %lu ns/op\n", __func__, (tend - tstart)/size);
}

int test_reverse_variantkey(mmfile_t vknr)
Expand Down Expand Up @@ -178,7 +178,7 @@ void benchmark_reverse_variantkey(mmfile_t vknr)
reverse_variantkey(vknr.src, vknr.last, 0xb000c35b64690b25, &rev);
}
tend = get_time();
fprintf(stdout, " * %s : %lu ns/op\n", __func__, (tend - tstart)/(size*4));
fprintf(stdout, " * %s : %lu ns/op\n", __func__, (tend - tstart)/size);
}

int main()
Expand Down
10 changes: 5 additions & 5 deletions c/test/test_rsidvar.c
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ void benchmark_get_vr_rsid(mmfile_t vr)
get_vr_rsid(vr.src, 3);
}
tend = get_time();
fprintf(stdout, " * %s : %lu ns/op\n", __func__, (tend - tstart)/(size*4));
fprintf(stdout, " * %s : %lu ns/op\n", __func__, (tend - tstart)/size);
}

void benchmark_get_rv_variantkey(mmfile_t rv)
Expand All @@ -290,7 +290,7 @@ void benchmark_get_rv_variantkey(mmfile_t rv)
get_rv_variantkey(rv.src, 3);
}
tend = get_time();
fprintf(stdout, " * %s : %lu ns/op\n", __func__, (tend - tstart)/(size*4));
fprintf(stdout, " * %s : %lu ns/op\n", __func__, (tend - tstart)/size);
}

void benchmark_find_rv_variantkey_by_rsid(mmfile_t rv)
Expand All @@ -306,7 +306,7 @@ void benchmark_find_rv_variantkey_by_rsid(mmfile_t rv)
find_rv_variantkey_by_rsid(rv.src, &first, 9, 0x2F81F575);
}
tend = get_time();
fprintf(stdout, " * %s : %lu ns/op\n", __func__, (tend - tstart)/(size*4));
fprintf(stdout, " * %s : %lu ns/op\n", __func__, (tend - tstart)/size);
}

void benchmark_find_vr_rsid_by_variantkey(mmfile_t vr)
Expand All @@ -322,7 +322,7 @@ void benchmark_find_vr_rsid_by_variantkey(mmfile_t vr)
find_vr_rsid_by_variantkey(vr.src, &first, 9, 0X160017CCA313D0E0);
}
tend = get_time();
fprintf(stdout, " * %s : %lu ns/op\n", __func__, (tend - tstart)/(size*4));
fprintf(stdout, " * %s : %lu ns/op\n", __func__, (tend - tstart)/size);
}

void benchmark_find_vr_chrompos_range(mmfile_t vr)
Expand All @@ -339,7 +339,7 @@ void benchmark_find_vr_chrompos_range(mmfile_t vr)
find_vr_chrompos_range(vr.src, &first, &last, 0x19, 0x001AF8FD, 0x001C8F2A);
}
tend = get_time();
fprintf(stdout, " * %s : %lu ns/op\n", __func__, (tend - tstart)/(size*4));
fprintf(stdout, " * %s : %lu ns/op\n", __func__, (tend - tstart)/size);
}

int main()
Expand Down
2 changes: 1 addition & 1 deletion conda/c.vk/meta.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package:
name: vk
version: 2.7.0
version: 2.7.1

source:
path: ../..
Expand Down
2 changes: 1 addition & 1 deletion conda/python/meta.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package:
name: variantkey
version: 2.7.0
version: 2.7.1

source:
path: ../..
Expand Down
2 changes: 1 addition & 1 deletion conda/r/meta.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package:
name: r-variantkey
version: 2.7.0
version: 2.7.1

source:
path: ../..
Expand Down
2 changes: 1 addition & 1 deletion python/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def run(self):

setup(
name='variantkey',
version='2.7.0',
version='2.7.1',
keywords=('variantkey variant key genetic genomics'),
description="VariantKey Bindings for Python",
long_description=read('../README.md'),
Expand Down
2 changes: 1 addition & 1 deletion r/variantkey/DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: variantkey
Title: Genetic VariantKey
Version: 2.7.0.1
Version: 2.7.1.1
Authors@R: person("Nicola", "Asuni", email = "info@genomicsplc.com", role = c("aut", "cre"))
Description: Tools to generate and process a 64 bit Unsigned Integer Keys for Human Genetic Variants.
The VariantKey is sortable for chromosome and position,
Expand Down

0 comments on commit 6808ecb

Please sign in to comment.