Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "vectorfighter.h"
- VectorFighter::VectorFighter()
- {
- vector.reserve(SIZE);
- }
- void VectorFighter::fillVector(double *values)
- {
- timer.start();
- for(int i = 0; i < SIZE; i++){
- vector.append(values[i]);
- }
- qDebug()<<"Vector write elapsed time: "<<timer.nsecsElapsed();
- }
- void VectorFighter::dumpVector()
- {
- timer.start();
- double *temp = new double[SIZE];
- for(int i = 0; i < vector.count(); i++){
- temp[i] = vector[i];
- }
- qDebug()<<"Vector read elapsed time: "<<timer.nsecsElapsed();
- }
- //---------------------------------------------------------------------------------------------
- #include "hashfighter.h"
- HashFighter::HashFighter()
- {
- hash.reserve(SIZE);
- }
- void HashFighter::fillHash(double *values)
- {
- timer.start();
- for(int i = 0; i < SIZE; i++){
- hash.insert(i, values[i]);
- }
- qDebug()<<"Hash write elapsed time: "<<timer.nsecsElapsed();
- }
- void HashFighter::dumpHash()
- {
- timer.start();
- QList<int> keys = hash.keys();
- double *temp = new double[SIZE];
- for(int i = 0; i < keys.count(); i++){
- temp[i] = hash[keys[i]];
- }
- qDebug()<<"Hash read elapsed time: "<<timer.nsecsElapsed();
- }
- //---------------------------------------------------------------------------------------------
- #include <vectorfighter.h>
- #include <hashfighter.h>
- #include <cstdlib>
- int main(int argc, char *argv[])
- {
- VectorFighter *vector = new VectorFighter();
- HashFighter *hash = new HashFighter();
- double *values = new double[1000];
- for(int i = 0; i < 1000; i++){
- values[i] = rand()%100 / rand()%99;
- }
- vector->fillVector(values);
- vector->dumpVector();
- hash->fillHash(values);
- hash->dumpHash();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement