class FrecencyStorageTest : public ::testing::Test { protected:
RefPtr<CacheIndexRecordWrapper> MakeRecord(uint32_t frecency) { auto* rec = new CacheIndexRecordWrapper();
rec->Get()->mFrecency = frecency; return RefPtr<CacheIndexRecordWrapper>(rec);
}
};
// Test to ensure that AppendRecord and RemoveRecord work correctly. Also // implicitly tests RecordExistedUnlocked
TEST_F(FrecencyStorageTest, AppendRemoveRecordTest) {
CacheIndex::FrecencyStorage storage;
RefPtr<CacheIndexRecordWrapper> rec1 = MakeRecord(10);
RefPtr<CacheIndexRecordWrapper> rec2 = MakeRecord(20);
// Test to ensure that ReplaceRecord updates the record correctly.
TEST_F(FrecencyStorageTest, ReplaceRecordTest) {
RefPtr<CacheIndexRecordWrapper> oldRec = MakeRecord(10);
RefPtr<CacheIndexRecordWrapper> newRec = MakeRecord(20);
// Test to ensure that GetSortedSnapshotForEviction returns records in sorted // order based on frecency.
TEST_F(FrecencyStorageTest, GetSortedSnapshotForEvictionTest) { auto r1 = MakeRecord(30); auto r2 = MakeRecord(10); auto r3 = MakeRecord(20);
// Performance test to ensure that AppendRecord and RemoveRecord do not degrade // with large numbers of records.
TEST_F(FrecencyStorageTest, PerformanceTest) {
constexpr int N = 100'000;
CacheIndex::FrecencyStorage storage;
std::vector<RefPtr<CacheIndexRecordWrapper>> records;
records.reserve(N); for (int i = 0; i < N; ++i) {
records.push_back(MakeRecord(i));
}
mozilla::StaticMutexAutoLock lock(CacheIndex::sLock);
// Utility function to measure the time taken auto measure = [](const std::function<void()>& func) { auto start = std::chrono::high_resolution_clock::now();
func(); auto end = std::chrono::high_resolution_clock::now(); return std::chrono::duration<double, std::milli>(end - start).count();
};
// Measure AppendRecord performance auto append_duration = measure([&] { for (constauto& rec : records) {
storage.AppendRecord(rec.get(), lock);
}
});
EXPECT_LE(append_duration, 200)
<< "AppendRecord is too slow" << " (" << append_duration << " ms) for "
<< N << " records";
// Measure ContainsRecord auto contains_duration = measure([&] { for (constauto& rec : records) { auto res = storage.RecordExistedUnlocked(rec.get());
EXPECT_TRUE(res); // Avoid any loop optimizations by adding this check if (!res) { break;
}
}
});
EXPECT_LE(contains_duration, 100)
<< "ContainsRecord is too slow" << " (" << contains_duration
<< " ms) for " << N << " records";
// Measure RemoveRecord performance auto remove_duration = measure([&] { for (constauto& rec : records) {
storage.RemoveRecord(rec.get(), lock);
}
});
EXPECT_LE(remove_duration, 200)
<< "RemoveRecord is too slow" << " (" << remove_duration << " ms) for "
<< N << " records";
}
} // namespace net
} // namespace mozilla
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.20 Sekunden
(vorverarbeitet am 2026-09-28)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.