LCOV - code coverage report
Current view: top level - tests - lfQueue.cpp (source / functions) Hit Total Coverage
Test: Lunchbox Lines: 37 37 100.0 %
Date: 2016-03-29 17:09:06 Functions: 6 7 85.7 %

          Line data    Source code
       1             : 
       2             : /* Copyright (c) 2010-2011, Stefan Eilemann <eile@equalizergraphics.com>
       3             :  *
       4             :  * This library is free software; you can redistribute it and/or modify it under
       5             :  * the terms of the GNU Lesser General Public License version 2.1 as published
       6             :  * by the Free Software Foundation.
       7             :  *
       8             :  * This library is distributed in the hope that it will be useful, but WITHOUT
       9             :  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
      10             :  * FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
      11             :  * details.
      12             :  *
      13             :  * You should have received a copy of the GNU Lesser General Public License
      14             :  * along with this library; if not, write to the Free Software Foundation, Inc.,
      15             :  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
      16             :  */
      17             : 
      18             : #include <test.h>
      19             : #include <lunchbox/clock.h>
      20             : #include <lunchbox/lfQueue.h>
      21             : #include <lunchbox/thread.h>
      22             : #include <iostream>
      23             : 
      24             : #define RUNTIME 1000 /*ms*/
      25             : 
      26           1 : lunchbox::LFQueue< uint64_t > queue(1024);
      27             : 
      28           1 : class ReadThread : public lunchbox::Thread
      29             : {
      30             : public:
      31           1 :     virtual ~ReadThread() {}
      32           1 :     virtual void run()
      33             :         {
      34           1 :             uint64_t nOps = 0;
      35           1 :             uint64_t nEmpty = 0;
      36           1 :             uint64_t item = 0xffffffffffffffffull;
      37             : 
      38           1 :             lunchbox::Clock clock;
      39      111578 :             while( clock.getTime64() < RUNTIME )
      40             :             {
      41      111576 :                 if( queue.getFront( item ))
      42             :                 {
      43      111576 :                     TEST( item == nOps );
      44      111576 :                     uint64_t item2 = 0xffffffffffffffffull;
      45      111576 :                     TEST( queue.pop( item2 ));
      46      111576 :                     TEST( item2 == item );
      47      111576 :                     ++nOps;
      48             :                 }
      49      111576 :                 TEST( item + 1 == nOps );
      50      111576 :                 ++nEmpty;
      51             :             }
      52           1 :             const float time = clock.getTimef();
      53           1 :             std::cout << 2*nOps/time << " reads/ms, " << nEmpty/time
      54           1 :                       << " empty/ms" << std::endl;
      55           1 :         }
      56             : };
      57             : 
      58           1 : int main( int, char** )
      59             : {
      60           1 :     ReadThread reader;
      61           1 :     uint64_t nOps = 0;
      62           1 :     uint64_t nEmpty = 0;
      63             : 
      64           1 :     TEST( reader.start( ));
      65             : 
      66           2 :     lunchbox::Clock clock;
      67       98906 :     while( clock.getTime64() < RUNTIME )
      68             :     {
      69      310319 :         while( queue.push( nOps ))
      70      112511 :             ++nOps;
      71       98904 :         ++nEmpty;
      72             :     }
      73           1 :     const float time = clock.getTimef();
      74             : 
      75           1 :     TEST( reader.join( ));
      76           1 :     std::cout << nOps/time << " writes/ms, " << nEmpty/time << " full/ms"
      77           1 :               << std::endl;
      78             : 
      79           2 :     return EXIT_SUCCESS;
      80           3 : }

Generated by: LCOV version 1.11