ALib C++ Library
Library Version: 2511 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) {
35 fmt.Reset();
36
37 Ticks::Duration tWrite;
38 Ticks::Duration tRead;
39
40 size_t allSizes = 0;
41 size_t winnerSizes= 0;
42 ALIB_DBG(int check= 0;)
43
44 result << "-------------------------------------------------------------------\n";
45 fmt.Format( result, "{} ({} arrays compressed)\n", headline, ctdCompressions );
46 fmt.Format( result, A_WCHAR("#Algo \u2205writeTime \u2205readTime \u2205 Size \u2205 Sz-Won wins\n" ));
47 result << "-------------------------------------------------------------------\n";
48 for( int algoNo= 0; algoNo < ArrayCompressor::NumberOfAlgorithms ; ++algoNo ) {
49 String128 sizeWhenWon;
50 if( sumUnCompressedWon[algoNo] )
51 fmt.Format( sizeWhenWon, "{:f5.1}%",
52 double(100 * sumCompressedWon[algoNo]) / double(sumUnCompressedWon[algoNo]) );
53 else
54 sizeWhenWon= "-/-";
55
56 String128 avgReadTime;
57 if( readTimes [algoNo].InNanoseconds() )
58 fmt.Format( avgReadTime, "{:>11,}",
59 readTimes [algoNo].InNanoseconds() / (ctdReads[algoNo] ? ctdReads[algoNo] : 1 ) );
60 else
61 avgReadTime= "-/-";
62
63 fmt.Format( result,
64 "{:13} {:>8,} {:>11} {:f5.1}% {:>6} {:f3.0}% ({:4})\n"
65 , ToBitwiseEnumeration<Algorithm>( algoNo )
66 , writeTimes[algoNo].InNanoseconds() / ctdCompressions
67 , avgReadTime
68 , double(100 * sumCompressed[algoNo]) / double(sumUncompressed)
69 , sizeWhenWon
70 , double(100 * ctdWins [algoNo]) / ctdCompressions
71 , ctdWins [algoNo] );
72
73 ALIB_DBG(check+= ctdWins[algoNo];)
74
75 tWrite += writeTimes [algoNo];
76 tRead += readTimes [algoNo];
77 allSizes += sumCompressed [algoNo];
78 winnerSizes+= sumCompressedWon[algoNo];
79 }
80
81 ALIB_ASSERT_ERROR( check==ctdCompressions, "BITBUFFER/AC",
82 "Error in ArrayCompressor::ExecutionStats: #algo wins do not sum up to #compressions: {} != ",
83 check, ctdCompressions )
84 if( printTotals) {
85 result << " -----------------------------------------------------------\n";
86
87 fmt.Format( result, " Totals:{:>7,} {:>11,} {:f5.1}% {:f5.1}%\n"
88 , tWrite.InNanoseconds() / ( ctdCompressions * ArrayCompressor::NumberOfAlgorithms )
89 , tRead .InNanoseconds() / ctdCompressions
90 , double(100 * allSizes ) / double( ArrayCompressor::NumberOfAlgorithms * sumUncompressed )
91 , double(100 * winnerSizes) / double(sumUncompressed) );
92 }
93 result.NewLine();
94}
95
96#endif // #if ALIB_CAMP
97
98}}} // namespace [alib::bitbuffer::ac_v1]
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:1340
#define ALIB_DBG(...)
Definition alib.inl:853
#define ALIB_ASSERT_ERROR(cond, domain,...)
Definition alib.inl:1066
#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:2189
int ctdCompressions
The number of executed compressions.
Definition ac.inl:297
size_t sumUnCompressedWon[NumberOfAlgorithms]
Definition ac.inl:291
size_t sumCompressed[NumberOfAlgorithms]
For each algorithm, the sum of resulting bytes of all compressions performed.
Definition ac.inl:281
Ticks::Duration readTimes[NumberOfAlgorithms]
The overall decompression time of each algorithm.
Definition ac.inl:271
size_t sumCompressedWon[NumberOfAlgorithms]
Definition ac.inl:286
int ctdReads[NumberOfAlgorithms]
The number of measured decompression runs of each algorithm.
Definition ac.inl:274
size_t sumUncompressed
The overall given array data to compress.
Definition ac.inl:294
Ticks::Duration writeTimes[NumberOfAlgorithms]
The overall compression time of each algorithm.
Definition ac.inl:268