1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-07-31 16:09:28 +02:00

AUP3: Fix assertions in Benchmark on 64-bit Windows build

Since size_t is different on 64-bit vs 32-bit Windows builds
it was causing assertions when displaying the results.

You can also change the sample format now by adjusting the
defines at the start of the source.
This commit is contained in:
Leland Lucius 2020-07-09 13:11:27 -05:00
parent 5b4c9b3425
commit 2e4812b148

View File

@ -47,6 +47,11 @@ of the BlockFile system.
#include "widgets/AudacityMessageBox.h"
#include "widgets/wxPanelWrapper.h"
// Change these to the desired format...should probably make the
// choice available in the dialog
#define SampleType short
#define SampleFormat int16Sample
class BenchmarkDialog final : public wxDialogWrapper
{
public:
@ -371,33 +376,34 @@ void BenchmarkDialog::OnRun( wxCommandEvent & WXUNUSED(event))
const auto t =
TrackFactory{ mSettings,
SampleBlockFactory::New( mProject ),
&zoomInfo }.NewWaveTrack(int16Sample);
&zoomInfo }.NewWaveTrack(SampleFormat);
t->SetRate(1);
srand(randSeed);
size_t nChunks, chunkSize;
//chunkSize = 7500 + (rand() % 1000);
chunkSize = 200 + (rand() % 100);
nChunks = (dataSize * 1048576) / (chunkSize*sizeof(short));
while(nChunks < 20 || chunkSize > ((unsigned long)(blockSize)*1024)/4) {
chunkSize = std::max( size_t(1), (chunkSize / 2) + (rand() % 100) );
nChunks = (dataSize * 1048576) / (chunkSize*sizeof(short));
uint64_t nChunks, chunkSize;
//chunkSize = 7500ull + (rand() % 1000ull);
chunkSize = 200ull + (rand() % 100ull);
nChunks = (dataSize * 1048576ull) / (chunkSize*sizeof(SampleType));
while (nChunks < 20 || chunkSize > (blockSize*1024)/4)
{
chunkSize = std::max( uint64_t(1), (chunkSize / 2) + (rand() % 100) );
nChunks = (dataSize * 1048576ull) / (chunkSize*sizeof(SampleType));
}
// The chunks are the pieces we move around in the test.
// They are (and are supposed to be) a different size to
// the blocks that make the blockfiles. That way we get to
// do some testing of when edit chunks cross blockfile boundaries.
Printf( XO("Using %ld chunks of %ld samples each, for a total of %.1f MB.\n")
.Format( nChunks, chunkSize, nChunks*chunkSize*sizeof(short)/1048576.0 ) );
Printf( XO("Using %lld chunks of %lld samples each, for a total of %.1f MB.\n")
.Format( nChunks, chunkSize, nChunks*chunkSize*sizeof(SampleType)/1048576.0 ) );
int trials = numEdits;
using Shorts = ArrayOf < short > ;
Shorts small1{ nChunks };
Shorts block{ chunkSize };
using Samples = ArrayOf<SampleType>;
Samples small1{nChunks};
Samples block{chunkSize};
Printf( XO("Preparing...\n") );
@ -411,13 +417,13 @@ void BenchmarkDialog::OnRun( wxCommandEvent & WXUNUSED(event))
wxString tempStr;
wxStopWatch timer;
for (size_t i = 0; i < nChunks; i++) {
v = short(rand());
for (uint64_t i = 0; i < nChunks; i++) {
v = SampleType(rand());
small1[i] = v;
for (size_t b = 0; b < chunkSize; b++)
for (uint64_t b = 0; b < chunkSize; b++)
block[b] = v;
t->Append((samplePtr)block.get(), int16Sample, chunkSize);
t->Append((samplePtr)block.get(), SampleFormat, chunkSize);
}
t->Flush();
@ -427,7 +433,7 @@ void BenchmarkDialog::OnRun( wxCommandEvent & WXUNUSED(event))
t->GetEndTime();
if (t->GetClipByIndex(0)->GetSequence()->GetNumSamples() != nChunks * chunkSize) {
Printf( XO("Expected len %ld, track len %lld.\n")
Printf( XO("Expected len %lld, track len %lld.\n")
.Format(
nChunks * chunkSize,
t->GetClipByIndex(0)->GetSequence()->GetNumSamples()
@ -443,13 +449,13 @@ void BenchmarkDialog::OnRun( wxCommandEvent & WXUNUSED(event))
for (z = 0; z < trials; z++) {
// First chunk to cut
// 0 <= x0 < nChunks
const size_t x0 = rand() % nChunks;
const uint64_t x0 = rand() % nChunks;
// Number of chunks to cut
// 1 <= xlen <= nChunks - x0
const size_t xlen = 1 + (rand() % (nChunks - x0));
const uint64_t xlen = 1 + (rand() % (nChunks - x0));
if (mEditDetail)
Printf( XO("Cut: %ld - %ld \n")
Printf( XO("Cut: %lld - %lld \n")
.Format( x0 * chunkSize, (x0 + xlen) * chunkSize) );
Track::Holder tmp;
@ -458,9 +464,9 @@ void BenchmarkDialog::OnRun( wxCommandEvent & WXUNUSED(event))
}
catch (const AudacityException&) {
Printf( XO("Trial %d\n").Format( z ) );
Printf( XO("Cut (%ld, %ld) failed.\n")
Printf( XO("Cut (%lld, %lld) failed.\n")
.Format( (x0 * chunkSize), (x0 + xlen) * chunkSize) );
Printf( XO("Expected len %ld, track len %lld.\n")
Printf( XO("Expected len %lld, track len %lld.\n")
.Format(
nChunks * chunkSize,
t->GetClipByIndex(0)->GetSequence()->GetNumSamples()
@ -470,10 +476,10 @@ void BenchmarkDialog::OnRun( wxCommandEvent & WXUNUSED(event))
// Position to paste
// 0 <= y0 <= nChunks - xlen
const size_t y0 = rand() % (nChunks - xlen + 1);
const uint64_t y0 = rand() % (nChunks - xlen + 1);
if (mEditDetail)
Printf( XO("Paste: %ld\n").Format( y0 * chunkSize ) );
Printf( XO("Paste: %lld\n").Format( y0 * chunkSize ) );
try {
t->Paste((double)(y0 * chunkSize), tmp.get());
@ -485,7 +491,7 @@ void BenchmarkDialog::OnRun( wxCommandEvent & WXUNUSED(event))
if (t->GetClipByIndex(0)->GetSequence()->GetNumSamples() != nChunks * chunkSize) {
Printf( XO("Trial %d\n").Format( z ) );
Printf( XO("Expected len %ld, track len %lld.\n")
Printf( XO("Expected len %lld, track len %lld.\n")
.Format(
nChunks * chunkSize,
t->GetClipByIndex(0)->GetSequence()->GetNumSamples()
@ -525,21 +531,21 @@ void BenchmarkDialog::OnRun( wxCommandEvent & WXUNUSED(event))
bad = 0;
timer.Start();
for (size_t i = 0; i < nChunks; i++) {
for (uint64_t i = 0; i < nChunks; i++) {
v = small1[i];
t->Get((samplePtr)block.get(), int16Sample, i * chunkSize, chunkSize);
for (size_t b = 0; b < chunkSize; b++)
t->Get((samplePtr)block.get(), SampleFormat, i * chunkSize, chunkSize);
for (uint64_t b = 0; b < chunkSize; b++)
if (block[b] != v) {
bad++;
if (bad < 10)
Printf( XO("Bad: chunk %ld sample %ld\n").Format( i, b ) );
Printf( XO("Bad: chunk %lld sample %lld\n").Format( i, b ) );
b = chunkSize;
}
}
if (bad == 0)
Printf( XO("Passed correctness check!\n") );
else
Printf( XO("Errors in %d/%ld chunks\n").Format( bad, nChunks ) );
Printf( XO("Errors in %d/%lld chunks\n").Format( bad, nChunks ) );
elapsed = timer.Time();
@ -551,10 +557,10 @@ void BenchmarkDialog::OnRun( wxCommandEvent & WXUNUSED(event))
timer.Start();
for (size_t i = 0; i < nChunks; i++) {
for (uint64_t i = 0; i < nChunks; i++) {
v = small1[i];
t->Get((samplePtr)block.get(), int16Sample, i * chunkSize, chunkSize);
for (size_t b = 0; b < chunkSize; b++)
t->Get((samplePtr)block.get(), SampleFormat, i * chunkSize, chunkSize);
for (uint64_t b = 0; b < chunkSize; b++)
if (block[b] != v)
bad++;
}
@ -563,8 +569,8 @@ void BenchmarkDialog::OnRun( wxCommandEvent & WXUNUSED(event))
Printf( XO("Time to check all data (2): %ld ms\n").Format( elapsed ) );
Printf( XO("At 44100 Hz, 16-bits per sample, the estimated number of\n simultaneous tracks that could be played at once: %.1f\n" )
.Format( (nChunks*chunkSize/44100.0)/(elapsed/1000.0) ) );
Printf( XO("At 44100 Hz, %d bytes per sample, the estimated number of\n simultaneous tracks that could be played at once: %.1f\n" )
.Format( SAMPLE_SIZE(SampleFormat), (nChunks*chunkSize/44100.0)/(elapsed/1000.0) ) );
goto success;