[#BloombergLP-bslmt-ThroughputBenchmark]
= xref:BloombergLP.adoc[BloombergLP]::xref:BloombergLP/bslmt.adoc[bslmt]::ThroughputBenchmark
:relfileprefix: ../../
:mrdocs:

This class is a mechanism that provides performance testing for multi&hyphen; threaded components&period; It allows running different thread functions at the same time, and simulates a work load between subsequent calls to the tested thread functions&period; The results are loaded into a `bslmt&colon;&colon;ThroughputBenchmarkResult` object, which provides access to counts of the work done by each thread, thread group, and sample, divided by the number of actual seconds of execution&period;

== Synopsis

Declared in `&lt;bslmt&lowbar;throughputbenchmark&period;h&gt;`

[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
class ThroughputBenchmark;
----

== Types

[cols="1,4"]
|===
| Name| Description
| xref:BloombergLP/bslmt/ThroughputBenchmark/ThreadGroup.adoc[`ThreadGroup`] 
| Data used by a thread group
|===


== Type Aliases

[cols="1,4"]
|===
| Name| Description
| xref:BloombergLP/bslmt/ThroughputBenchmark/CleanupSampleFunction.adoc[`CleanupSampleFunction`] 
| An alias to a function meeting the following contract&colon; &grave; &sol;&sol;&sol; Clean up after the sample run&period; If the specified `isLast` is &sol;&sol;&sol; `true`, this is the last sample run&period; void cleanupSample(bool isLast)&semi; &grave;
| xref:BloombergLP/bslmt/ThroughputBenchmark/CleanupThreadFunction.adoc[`CleanupThreadFunction`] 
| An alias to a function meeting the following contract&colon; &grave; &sol;&sol;&sol; Clean up after each thread in a sample run&period; void cleanupThread()&semi; &grave;
| xref:BloombergLP/bslmt/ThroughputBenchmark/InitializeSampleFunction.adoc[`InitializeSampleFunction`] 
| An alias to a function meeting the following contract&colon; &grave; &sol;&sol;&sol; Initialize the sample run&period; If the specified `isFirst` is `true`, &sol;&sol;&sol; this is the first sample run&period; void initializeSample(bool isFirst)&semi; &grave;
| xref:BloombergLP/bslmt/ThroughputBenchmark/InitializeThreadFunction.adoc[`InitializeThreadFunction`] 
| An alias to a function meeting the following contract&colon; &grave; &sol;&sol;&sol; Initialize each thread in a sample run&period; void initializeThread()&semi; &grave;
| xref:BloombergLP/bslmt/ThroughputBenchmark/RunFunction.adoc[`RunFunction`] 
| An alias to a function meeting the following contract&colon; &grave; &sol;&sol;&sol; Run the main part of the benchmark having the specified &sol;&sol;&sol; `threadIndex`&period; The behavior is undefined unless `threadIndex` is &sol;&sol;&sol; in the range `&lsqb;0, numThreadsInGroup)&rsqb;`, where `numThreadsInGroup` is &sol;&sol;&sol; the number of threads in a thread group for the associated &sol;&sol;&sol; throughput benchmark&period; void runTest(int threadIndex)&semi; &grave;
| xref:BloombergLP/bslmt/ThroughputBenchmark/ShutdownSampleFunction.adoc[`ShutdownSampleFunction`] 
| An alias to a function meeting the following contract&colon; &grave; &sol;&sol;&sol; Clean up at the end of the sample run, before threads have been &sol;&sol;&sol; joined&period; If the specified `isLast` is `true`, this is the last &sol;&sol;&sol; sample run&period; void shutdownSample(bool isLast)&semi; &grave;
|===


== Member Functions

[cols="1,4"]
|===
| Name| Description
| xref:BloombergLP/bslmt/ThroughputBenchmark/2constructor.adoc[`ThroughputBenchmark`]         [.small]#[constructor]#
| Create an empty `ThroughputBenchmark` object&period; Optionally specify a `basicAllocator` used to supply memory&period; If `basicAllocator` is 0, the currently installed default allocator is used&period;
| xref:BloombergLP/bslmt/ThroughputBenchmark/addThreadGroup-01.adoc[`addThreadGroup`] 
| `addThreadGroup` overloads
| xref:BloombergLP/bslmt/ThroughputBenchmark/allocator.adoc[`allocator`] 
| Return the allocator used by this object&period;
| xref:BloombergLP/bslmt/ThroughputBenchmark/execute-06.adoc[`execute`] 
| `execute` overloads
| xref:BloombergLP/bslmt/ThroughputBenchmark/numThreadGroups.adoc[`numThreadGroups`] 
| Return the number of thread groups&period;
| xref:BloombergLP/bslmt/ThroughputBenchmark/numThreads.adoc[`numThreads`] 
| Return the total number of threads&period;
| xref:BloombergLP/bslmt/ThroughputBenchmark/numThreadsInGroup.adoc[`numThreadsInGroup`] 
| Return the number of threads in the specified `threadGroupIndex`&period; The behavior is undefined unless `0 &lt;&equals; threadGroupIndex &lt; numThreadGroups()`&period;
| xref:BloombergLP/bslmt/ThroughputBenchmark/2conversion.adoc[`operator BloombergLP::bslmf::NestedTraitDeclaration&lt;ThroughputBenchmark, UsesBslmaAllocator&gt;`] 
| Declare that this type uses a `bslma` allocator&period;
|===


== Static Member Functions

[cols="1,4"]
|===
| Name| Description
| xref:BloombergLP/bslmt/ThroughputBenchmark/antiOptimization.adoc[`antiOptimization`] 
| Return the value calculated by `busyWork`&period; Note that this method is provided to prevent the compiler from optimizing the simulated workload away&period;
| xref:BloombergLP/bslmt/ThroughputBenchmark/busyWork.adoc[`busyWork`] 
| Perform arithmetic operations to consume an amount of time in linear relation to the specified `busyWorkAmount`&period; Note that the duration of `busyWork` invoked with a particular `busyWorkAmount` will vary with system load&period;
| xref:BloombergLP/bslmt/ThroughputBenchmark/estimateBusyWorkAmount.adoc[`estimateBusyWorkAmount`] 
| Return an estimate of the work amount so that `busyWork` invoked with the returned work amount executes, approximately, for the specified `duration`&period; Note that this estimate varies with system load&period;
|===


== Friends

[cols="1,4"]
|===
| Name| Description
| `xref:BloombergLP/bslmt/ThroughputBenchmark_TestUtil.adoc[BloombergLP::bslmt::ThroughputBenchmark&lowbar;TestUtil]`
| This class implements a test utility that gives the test driver access to the unexposed data members of `ThroughputBenchmark`&period;
| `xref:BloombergLP/bslmt/ThroughputBenchmark_WorkFunction.adoc[BloombergLP::bslmt::ThroughputBenchmark&lowbar;WorkFunction]`
| This class is the work function functor, being called for each work thread&period;
|===


[.small]#Created with https://www.mrdocs.com[MrDocs]#
