ALib C++ Library
Library Version: 2402 R1
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 !defined(ALIB_DOX)
10# if !defined(HPP_AWORX_ALIB_BITBUFFER_AC_V1)
12# endif
13# if ALIB_CAMP && !defined(HPP_ALIB_LANG_FORMAT_FORMATTER)
15# endif
16#endif // !defined(ALIB_DOX)
17
18namespace alib { namespace bitbuffer { namespace ac_v1 {
19
20#if ALIB_CAMP
21
23void ArrayCompressor::Statistics::Print( AString& result, const String& headline, bool printTotals)
24{
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, qtyCompressions );
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::QtyAlgorithms ; ++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() / (qtyReads[algoNo] ? qtyReads[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() / qtyCompressions
61#else
62 , "-/-"
63#endif
64 , avgReadTime
65 , double(100 * sumCompressed[algoNo]) / double(sumUncompressed)
66 , sizeWhenWon
67 , double(100 * qtyWins [algoNo]) / qtyCompressions
68 , qtyWins [algoNo] );
69
70 ALIB_DBG(check+= qtyWins[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==qtyCompressions, "BITBUFFER/AC",
81 "Error in ArrayCompressor::ExecutionStats: "
82 "#algo wins do not sum up to #compressions: ",
83 NString128() << check << "!=" << qtyCompressions )
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() / ( qtyCompressions * ArrayCompressor::QtyAlgorithms )
91 , tRead .InNanoseconds() / qtyCompressions
92#else
93 , "-/-", "-/-"
94#endif
95 , double(100 * allSizes ) / double( ArrayCompressor::QtyAlgorithms * sumUncompressed )
96 , double(100 * winnerSizes) / double(sumUncompressed) );
97 }
98 result << NewLine();
99
100 fmt->Release();
101}
103
104#endif // #if ALIB_CAMP
105
106}}} // namespace [alib::bitbuffer::ac_v1]
static constexpr int QtyAlgorithms
The number of algorithms implemented.
Definition ac.hpp:76
static SPFormatter AcquireDefault(const NCString &dbgFile, int dbgLine, const NCString &dbgFunc)
#define ALIB_WARNINGS_RESTORE
Definition alib.hpp:715
#define ALIB_ASSERT_ERROR(cond,...)
Definition alib.hpp:984
#define ALIB_WARNINGS_ALLOW_UNSAFE_BUFFER_USAGE
Definition alib.hpp:644
#define ALIB_DBG(...)
Definition alib.hpp:457
#define ALIB_CALLER_PRUNED
Definition alib.hpp:845
#define A_WCHAR(STR)
#define ALIB_TIME
Definition alib.hpp:181
Definition alib.cpp:57
NLocalString< 128 > NString128
Type alias name for TLocalString<nchar,128> .
constexpr CString NewLine()
Definition cstring.hpp:528
Ticks::Duration writeTimes[QtyAlgorithms]
Definition ac.hpp:347
Ticks::Duration readTimes[QtyAlgorithms]
Definition ac.hpp:350