ALib C++ Library
Library Version: 2412 R0
Documentation generated by doxygen
Loading...
Searching...
No Matches
ac.cpp
1// #################################################################################################
2// ALib C++ Library
3//
4// Copyright 2013-2024 A-Worx GmbH, Germany
5// Published under 'Boost Software License' (a free software license, see LICENSE.txt)
6// #################################################################################################
8
9#if !DOXYGEN
11# if ALIB_CAMP
13# endif
14#endif // !DOXYGEN
15
16namespace alib { namespace bitbuffer { namespace ac_v1 {
17
18#if ALIB_CAMP
19
21void ArrayCompressor::Statistics::Print( AString& result, const String& headline, bool printTotals)
22{
25 fmt.Reset();
26#if ALIB_TIME
27 Ticks::Duration tWrite;
28 Ticks::Duration tRead;
29#endif
30 size_t allSizes = 0;
31 size_t winnerSizes= 0;
32 ALIB_DBG(int check= 0;)
33
34 result << "-------------------------------------------------------------------\n";
35 fmt.Format( result, "{} ({} arrays compressed)\n", headline, ctdCompressions );
36 fmt.Format( result, A_WCHAR("#Algo \u2205writeTime \u2205readTime \u2205 Size \u2205 Sz-Won wins\n" ));
37 result << "-------------------------------------------------------------------\n";
38 for( int algoNo= 0; algoNo < ArrayCompressor::NumberOfAlgorithms ; ++algoNo )
39 {
40 String128 sizeWhenWon;
41 if( sumUnCompressedWon[algoNo] )
42 fmt.Format( sizeWhenWon, "{:f5.1}%",
43 double(100 * sumCompressedWon[algoNo]) / double(sumUnCompressedWon[algoNo]) );
44 else
45 sizeWhenWon= "-/-";
46
47 String128 avgReadTime;
48#if ALIB_TIME
49 if( readTimes [algoNo].InNanoseconds() )
50 fmt.Format( avgReadTime, "{:>11,}",
51 readTimes [algoNo].InNanoseconds() / (ctdReads[algoNo] ? ctdReads[algoNo] : 1 ) );
52 else
53#endif
54 avgReadTime= "-/-";
55
56 fmt.Format( result,
57 "{:13} {:>8,} {:>11} {:f5.1}% {:>6} {:f3.0}% ({:4})\n"
58 , ToBitwiseEnumeration<Algorithm>( algoNo )
59#if ALIB_TIME
60 , writeTimes[algoNo].InNanoseconds() / ctdCompressions
61#else
62 , "-/-"
63#endif
64 , avgReadTime
65 , double(100 * sumCompressed[algoNo]) / double(sumUncompressed)
66 , sizeWhenWon
67 , double(100 * ctdWins [algoNo]) / ctdCompressions
68 , ctdWins [algoNo] );
69
70 ALIB_DBG(check+= ctdWins[algoNo];)
71
72#if ALIB_TIME
73 tWrite += writeTimes [algoNo];
74 tRead += readTimes [algoNo];
75#endif
76 allSizes += sumCompressed [algoNo];
77 winnerSizes+= sumCompressedWon[algoNo];
78 }
79
80 ALIB_ASSERT_ERROR( check==ctdCompressions, "BITBUFFER/AC",
81 "Error in ArrayCompressor::ExecutionStats: "
82 "#algo wins do not sum up to #compressions: ",
83 NString128() << check << "!=" << ctdCompressions )
84 if( printTotals)
85 {
86 result << " -----------------------------------------------------------\n";
87
88 fmt.Format( result, " Totals:{:>7,} {:>11,} {:f5.1}% {:f5.1}%\n"
89#if ALIB_TIME
90 , tWrite.InNanoseconds() / ( ctdCompressions * ArrayCompressor::NumberOfAlgorithms )
91 , tRead .InNanoseconds() / ctdCompressions
92#else
93 , "-/-", "-/-"
94#endif
95 , double(100 * allSizes ) / double( ArrayCompressor::NumberOfAlgorithms * sumUncompressed )
96 , double(100 * winnerSizes) / double(sumUncompressed) );
97 }
98 result.NewLine();
99}
101
102#endif // #if ALIB_CAMP
103
104}}} // namespace [alib::bitbuffer::ac_v1]
105
static constexpr int NumberOfAlgorithms
The number of algorithms implemented.
Definition ac.hpp:54
static ALIB_API threads::RecursiveLock DefaultLock
static ALIB_API SPFormatter Default
virtual BoxesMA & Reset()
Formatter & Format(AString &target, TArgs &&... args)
#define ALIB_WARNINGS_RESTORE
Definition alib.hpp:849
#define ALIB_LOCK_RECURSIVE_WITH(lock)
Definition owner.hpp:457
#define ALIB_ASSERT_ERROR(cond,...)
Definition alib.hpp:1271
#define ALIB_WARNINGS_ALLOW_UNSAFE_BUFFER_USAGE
Definition alib.hpp:760
#define ALIB_DBG(...)
Definition alib.hpp:390
#define A_WCHAR(STR)
#define ALIB_TIME
Definition alib.hpp:214
Definition alib.cpp:69
NLocalString< 128 > NString128
Type alias name for TLocalString<nchar,128>.
int ctdReads[NumberOfAlgorithms]
The number of measured decompression runs of each algorithm.
Definition ac.hpp:312
Ticks::Duration writeTimes[NumberOfAlgorithms]
The overall compression time of each algorithm.
Definition ac.hpp:306
size_t sumCompressed[NumberOfAlgorithms]
For each algorithm, the sum of resulting bytes of all compressions performed.
Definition ac.hpp:320
size_t sumUncompressed
The overall given array data to compress.
Definition ac.hpp:333
Ticks::Duration readTimes[NumberOfAlgorithms]
The overall decompression time of each algorithm.
Definition ac.hpp:309
size_t sumCompressedWon[NumberOfAlgorithms]
Definition ac.hpp:325
size_t sumUnCompressedWon[NumberOfAlgorithms]
Definition ac.hpp:330
int ctdCompressions
The number of executed compressions.
Definition ac.hpp:336