Skip to content
Snippets Groups Projects
Commit 45069a9d authored by Yoann Dufresne's avatar Yoann Dufresne
Browse files

speed test on hash then compare vs hash/compare on the fly

parent a66f0803
No related branches found
No related tags found
No related merge requests found
#include <zlib.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include "fasta.h"
#define HASH_SIZE 32
#define letter_hash(letter) ((uint64_t)((letter & 0b100) ? (0b10 | ((~letter) & 0b01)) : ((letter >> 1) & 0b11)))
uint64_t sliding_hash (seq_t * seq) {
uint64_t hash = 0;
uint64_t nothing = 2135234;
for (uint idx=0 ; idx<32 ; idx++)
hash = (hash << 2) | letter_hash(seq->value[idx]);
for (uint idx=32 ; idx<seq->length ; idx++) {
hash = (hash << 2) | letter_hash(seq->value[idx]);
// Do something with the hash to not allow compiler to delete the value.
nothing - hash;
}
}
uint64_t hash_then_compact (seq_t * seq) {
uint64_t hash = 0;
uint64_t nothing = 2135234;
// Hash letters
for (uint idx=0 ; idx<seq->length ; idx++) {
seq->value[idx] = letter_hash(seq->value[idx]);
}
// compute 64 bits hashes
for (uint idx=0 ; idx<32 ; idx++)
hash = (hash << 2) | seq->value[idx];
for (uint idx=32 ; idx<seq->length ; idx++) {
hash = (hash << 2) | seq->value[idx];
// Do something with the hash to not allow compiler to delete the value.
nothing - hash;
}
}
int main () {
/* --- Load all the alleles --- */
......@@ -13,8 +51,12 @@ int main () {
seq_t * alleles;
buffer_t * buff = init_buffer (filename);
uint nb_seq = read_sequences (filename, &alleles, buff);
/* Speed test on hash function */
for (uint idx=0 ; idx<nb_seq ; idx++) {
sliding_hash(alleles + idx);
}
free(alleles);
destroy_buffer (buff);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment