Skip to content

Commit

Permalink
compute and display memory usage
Browse files Browse the repository at this point in the history
  • Loading branch information
tringi committed Sep 11, 2022
1 parent f82f7be commit daefe53
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
23 changes: 19 additions & 4 deletions test/SearchTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,19 @@ struct search : agsearch {
return true;
}

std::size_t usage () const {
auto cb = this->pattern.size () * sizeof (token);
for (const auto & token : this->pattern) {
if (token.value.length () >= 8) {
cb += token.value.length () * sizeof (wchar_t) + 8; // allocation overhead guess
}
if (token.alternative.length () >= 8) {
cb += token.alternative.length () * sizeof (wchar_t) + 8; // allocation overhead guess
}
}
return cb;
}

public:
LARGE_INTEGER perfhz;
LARGE_INTEGER perfT0;
Expand All @@ -39,9 +52,11 @@ struct search : agsearch {
auto t = 1000.0 * double (perfT1.QuadPart - this->perfT0.QuadPart) / double (this->perfhz.QuadPart);

wchar_t report [256];
std::swprintf (report, 256, L"%u results in %.2f ms (%s)",
(unsigned) results.size (), t,
full ? L"FULL RESCAN AND SEARCH" : L"search only");
std::swprintf (report, 256, L"%zu results in %.2f ms (%s) from %zu kB (%zu tokens)",
results.size (), t,
full ? L"FULL RESCAN AND SEARCH" : L"search only",
this->usage () / 1024, this->pattern.size ());

SetDlgItemText (hWnd, 902, report);
InvalidateRect (hWnd, NULL, FALSE);
}
Expand Down Expand Up @@ -661,7 +676,7 @@ LPCTSTR Initialize (HINSTANCE hInstance) {
int CALLBACK wWinMain (_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE, _In_ LPWSTR lpCmdLine, _In_ int nCmdShow) {
InitCommonControls ();
BufferedPaintInit ();

if (auto atom = Initialize (hInstance)) {
auto menu = LoadMenu (hInstance, MAKEINTRESOURCE (1));
auto accs = LoadAccelerators (hInstance, MAKEINTRESOURCE (1));
Expand Down
2 changes: 1 addition & 1 deletion test/SearchTest.info
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
major = 1
minor = 1
patch = 0
build = 497
build = 507

[versioninfo]
filename = %dir%\%internalname%-vi.rc
Expand Down

0 comments on commit daefe53

Please sign in to comment.