ALib C++ Library
Library Version: 2510 R0
Documentation generated by doxygen
Loading...
Searching...
No Matches
ac.cpp
1// #################################################################################################
2// ALib C++ Library
3//
4// Copyright 2013-2025 A-Worx GmbH, Germany
5// Published under 'Boost Software License' (a free software license, see LICENSE.txt)
6// #################################################################################################
7#include "alib_precompile.hpp"
8#if !defined(ALIB_C20_MODULES) || ((ALIB_C20_MODULES != 0) && (ALIB_C20_MODULES != 1))
9# error "Symbol ALIB_C20_MODULES has to be given to the compiler as either 0 or 1"
10#endif
11#if ALIB_C20_MODULES
12 module;
13#endif
14// ====================================== Global Fragment ======================================
16
17// =========================================== Module ==========================================
18#if ALIB_C20_MODULES
19 module ALib.BitBuffer;
20# if ALIB_FORMAT
21 import ALib.Format;
22# endif
23#else
24# include "ALib.Format.H"
25# include "ALib.BitBuffer.H"
26#endif
27// ====================================== Implementation =======================================
28namespace alib { namespace bitbuffer { namespace ac_v1 {
29
30#if ALIB_FORMAT
31
32void ArrayCompressor::Statistics::Print( AString& result, const String& headline, bool printTotals)
33{
36 fmt.Reset();
37
38 Ticks::Duration tWrite;
39 Ticks::Duration tRead;
40
41 size_t allSizes = 0;
42 size_t winnerSizes= 0;
43 ALIB_DBG(int check= 0;)
44
45 result << "-------------------------------------------------------------------\n";
46 fmt.Format( result, "{} ({} arrays compressed)\n", headline, ctdCompressions );
47 fmt.Format( result, A_WCHAR("#Algo \u2205writeTime \u2205readTime \u2205 Size \u2205 Sz-Won wins\n" ));
48 result << "-------------------------------------------------------------------\n";
49 for( int algoNo= 0; algoNo < ArrayCompressor::NumberOfAlgorithms ; ++algoNo )
50 {
51 String128 sizeWhenWon;
52 if( sumUnCompressedWon[algoNo] )
53 fmt.Format( sizeWhenWon, "{:f5.1}%",
54 double(100 * sumCompressedWon[algoNo]) / double(sumUnCompressedWon[algoNo]) );
55 else
56 sizeWhenWon= "-/-";
57
58 String128 avgReadTime;
59 if( readTimes [algoNo].InNanoseconds() )
60 fmt.Format( avgReadTime, "{:>11,}",
61 readTimes [algoNo].InNanoseconds() / (ctdReads[algoNo] ? ctdReads[algoNo] : 1 ) );
62 else
63 avgReadTime= "-/-";
64
65 fmt.Format( result,
66 "{:13} {:>8,} {:>11} {:f5.1}% {:>6} {:f3.0}% ({:4})\n"
67 , ToBitwiseEnumeration<Algorithm>( algoNo )
68 , writeTimes[algoNo].InNanoseconds() / ctdCompressions
69 , avgReadTime
70 , double(100 * sumCompressed[algoNo]) / double(sumUncompressed)
71 , sizeWhenWon
72 , double(100 * ctdWins [algoNo]) / ctdCompressions
73 , ctdWins [algoNo] );
74
75 ALIB_DBG(check+= ctdWins[algoNo];)
76
77 tWrite += writeTimes [algoNo];
78 tRead += readTimes [algoNo];
79 allSizes += sumCompressed [algoNo];
80 winnerSizes+= sumCompressedWon[algoNo];
81 }
82
83 ALIB_ASSERT_ERROR( check==ctdCompressions, "BITBUFFER/AC",
84 "Error in ArrayCompressor::ExecutionStats: #algo wins do not sum up to #compressions: {} != ",
85 check, ctdCompressions )
86 if( printTotals)
87 {
88 result << " -----------------------------------------------------------\n";
89
90 fmt.Format( result, " Totals:{:>7,} {:>11,} {:f5.1}% {:f5.1}%\n"
91 , tWrite.InNanoseconds() / ( ctdCompressions * ArrayCompressor::NumberOfAlgorithms )
92 , tRead .InNanoseconds() / ctdCompressions
93 , double(100 * allSizes ) / double( ArrayCompressor::NumberOfAlgorithms * sumUncompressed )
94 , double(100 * winnerSizes) / double(sumUncompressed) );
95 }
96 result.NewLine();
97}
98
99#endif // #if ALIB_CAMP
100
101}}} // namespace [alib::bitbuffer::ac_v1]
102
static constexpr int NumberOfAlgorithms
The number of algorithms implemented.
Definition ac.inl:40
static ALIB_DLL threads::RecursiveLock DefaultLock
Formatter & Format(AString &target, TArgs &&... args)
static ALIB_DLL SPFormatter Default
virtual BoxesMA & Reset()
#define ALIB_LOCK_RECURSIVE_WITH(lock)
Definition alib.inl:1323
#define ALIB_DBG(...)
Definition alib.inl:836
#define ALIB_ASSERT_ERROR(cond, domain,...)
Definition alib.inl:1049
#define A_WCHAR(STR)
strings::TAString< character, lang::HeapAllocator > AString
Type alias in namespace alib.
LocalString< 128 > String128
Type alias name for TLocalString<character,128>.
format::Formatter Formatter
Type alias in namespace alib.
strings::TString< character > String
Type alias in namespace alib.
Definition string.inl:2381
int ctdCompressions
The number of executed compressions.
Definition ac.inl:314
size_t sumUnCompressedWon[NumberOfAlgorithms]
Definition ac.inl:308
size_t sumCompressed[NumberOfAlgorithms]
For each algorithm, the sum of resulting bytes of all compressions performed.
Definition ac.inl:298
Ticks::Duration readTimes[NumberOfAlgorithms]
The overall decompression time of each algorithm.
Definition ac.inl:288
size_t sumCompressedWon[NumberOfAlgorithms]
Definition ac.inl:303
int ctdReads[NumberOfAlgorithms]
The number of measured decompression runs of each algorithm.
Definition ac.inl:291
size_t sumUncompressed
The overall given array data to compress.
Definition ac.inl:311
Ticks::Duration writeTimes[NumberOfAlgorithms]
The overall compression time of each algorithm.
Definition ac.inl:285