Changeset - 8ef18859c787
[Not reviewed]
longmem
0 1 0
Hasan Yavuz ÖZDERYA - 8 years ago 2017-08-13 06:45:13
hy@ozderya.net
added timing tests
1 file changed with 23 insertions and 0 deletions:
0 comments (0 inline, 0 general)
tests/test.cpp
Show inline comments
 
/*
 
  Copyright © 2017 Hasan Yavuz Özderya
 

	
 
  This file is part of serialplot.
 

	
 
  serialplot is free software: you can redistribute it and/or modify
 
  it under the terms of the GNU General Public License as published by
 
  the Free Software Foundation, either version 3 of the License, or
 
  (at your option) any later version.
 

	
 
  serialplot is distributed in the hope that it will be useful,
 
  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
  GNU General Public License for more details.
 

	
 
  You should have received a copy of the GNU General Public License
 
  along with serialplot.  If not, see <http://www.gnu.org/licenses/>.
 
*/
 

	
 
#include <time.h>
 
#define CATCH_CONFIG_MAIN  // This tells Catch to provide a main() - only do this in one cpp file
 
#include "catch.hpp"
 

	
 
#include "datachunk.h"
 
#include "chunkedbuffer.h"
 

	
 
TEST_CASE("DataChunk created empty", "[memory]")
 
{
 
    DataChunk c(0, 1000);
 
    REQUIRE(c.size() == 0);
 
    REQUIRE(c.capacity() == 1000);
 
    REQUIRE(c.start() == 0);
 
    REQUIRE(c.end() == 0);
 
    REQUIRE_FALSE(c.isFull());
 
    REQUIRE(c.left() == 1000);
 
}
 

	
 
TEST_CASE("adding data to DataChunk", "[memory]")
 
{
 
    DataChunk c(0, 1000);
 
    double samples[10] = {1,2,3,4,5,6,7,8,9,10};
 
    c.addSamples(samples, 10);
 

	
 
    REQUIRE(c.size() == 10);
 
@@ -126,24 +127,46 @@ TEST_CASE("ChunkedBuffer accessing data"
 
    ChunkedBuffer b;
 

	
 
    // prepare data
 
    double samples[CHUNK_SIZE*3];
 
    samples[0] = 10;
 
    samples[10] = 20;
 
    samples[CHUNK_SIZE-1] = 30;
 
    samples[CHUNK_SIZE] = 40;
 
    samples[CHUNK_SIZE+1] = 50;
 
    samples[CHUNK_SIZE*2-1] = 60;
 
    samples[CHUNK_SIZE*3-1] = 70;
 

	
 
    // test
 
    b.addSamples(samples, CHUNK_SIZE*3);
 

	
 
    REQUIRE(b.size() == CHUNK_SIZE*3);
 
    REQUIRE(b.sample(0) == 10);
 
    REQUIRE(b.sample(10) == 20);
 
    REQUIRE(b.sample(CHUNK_SIZE-1) == 30);
 
    REQUIRE(b.sample(CHUNK_SIZE) == 40);
 
    REQUIRE(b.sample(CHUNK_SIZE+1) == 50);
 
    REQUIRE(b.sample(CHUNK_SIZE*2-1) == 60);
 
    REQUIRE(b.sample(CHUNK_SIZE*3-1) == 70);
 
}
 

	
 
TEST_CASE("ChunkedBuffer time measurement", "[.][timing][memory]")
 
{
 
    const int N = CHUNK_SIZE*10;
 
    clock_t start, end;
 
    double samples[N];
 
    ChunkedBuffer b;
 
    start = clock();
 
    b.addSamples(samples, N);
 
    end = clock();
 
    REQUIRE(b.size() == N);
 
    WARN("addSamples(" << N << ") took: " << ((end-start) / ((double) CLOCKS_PER_SEC)));
 

	
 
    // access
 
    start = clock();
 
    for (int i =0; i < N; i++)
 
    {
 
        samples[i] = b.sample(i);
 
    }
 
    end = clock();
 
    WARN("sample()*"<< N <<" took: " << ((end-start) / ((double) CLOCKS_PER_SEC)));
 
}
0 comments (0 inline, 0 general)