[PATCH] D16726: [Profiling] Speed up unittests by ~5x
Vedant Kumar via llvm-commits
llvm-commits at lists.llvm.org
Fri Jan 29 17:04:36 PST 2016
vsk updated this revision to Diff 46454.
vsk added a comment.
- Rangify loops.
http://reviews.llvm.org/D16726
Files:
unittests/ProfileData/InstrProfTest.cpp
Index: unittests/ProfileData/InstrProfTest.cpp
===================================================================
--- unittests/ProfileData/InstrProfTest.cpp
+++ unittests/ProfileData/InstrProfTest.cpp
@@ -711,73 +711,26 @@
}
TEST_P(MaybeSparseInstrProfTest, instr_prof_symtab_compression_test) {
- std::vector<std::string> FuncNames1;
- std::vector<std::string> FuncNames2;
- for (int I = 0; I < 10 * 1024; I++) {
- std::string str;
- raw_string_ostream OS(str);
- OS << "func_" << I;
- FuncNames1.push_back(OS.str());
- str.clear();
- OS << "fooooooooooooooo_" << I;
- FuncNames1.push_back(OS.str());
- str.clear();
- OS << "BAR_" << I;
- FuncNames2.push_back(OS.str());
- str.clear();
- OS << "BlahblahBlahblahBar_" << I;
- FuncNames2.push_back(OS.str());
- }
-
- for (bool DoCompression : {false, true}) {
- // Compressing:
- std::string FuncNameStrings1;
- collectPGOFuncNameStrings(
- FuncNames1, (DoCompression && zlib::isAvailable()), FuncNameStrings1);
-
- // Compressing:
- std::string FuncNameStrings2;
- collectPGOFuncNameStrings(
- FuncNames2, (DoCompression && zlib::isAvailable()), FuncNameStrings2);
-
- for (int Padding = 0; Padding < 3; Padding++) {
- // Join with paddings:
- std::string FuncNameStrings = FuncNameStrings1;
- for (int P = 0; P < Padding; P++) {
- FuncNameStrings.push_back('\0');
- }
- FuncNameStrings += FuncNameStrings2;
-
- // Now decompress:
- InstrProfSymtab Symtab;
- Symtab.create(StringRef(FuncNameStrings));
-
- // Now do the checks:
- // First sampling some data points:
- StringRef R = Symtab.getFuncName(IndexedInstrProf::ComputeHash(FuncNames1[0]));
- ASSERT_EQ(StringRef("func_0"), R);
- R = Symtab.getFuncName(IndexedInstrProf::ComputeHash(FuncNames1[1]));
- ASSERT_EQ(StringRef("fooooooooooooooo_0"), R);
- R = Symtab.getFuncName(IndexedInstrProf::ComputeHash(FuncNames1[998]));
- ASSERT_EQ(StringRef("func_499"), R);
- R = Symtab.getFuncName(IndexedInstrProf::ComputeHash(FuncNames1[999]));
- ASSERT_EQ(StringRef("fooooooooooooooo_499"), R);
- R = Symtab.getFuncName(IndexedInstrProf::ComputeHash(FuncNames2[100]));
- ASSERT_EQ(StringRef("BAR_50"), R);
- R = Symtab.getFuncName(IndexedInstrProf::ComputeHash(FuncNames2[101]));
- ASSERT_EQ(StringRef("BlahblahBlahblahBar_50"), R);
- for (int I = 0; I < 10 * 1024; I++) {
- std::string N[4];
- N[0] = FuncNames1[2 * I];
- N[1] = FuncNames1[2 * I + 1];
- N[2] = FuncNames2[2 * I];
- N[3] = FuncNames2[2 * I + 1];
- for (int J = 0; J < 4; J++) {
- StringRef R = Symtab.getFuncName(IndexedInstrProf::ComputeHash(N[J]));
- ASSERT_EQ(StringRef(N[J]), R);
- }
- }
- }
+ if (!zlib::isAvailable())
+ return;
+
+ std::string NamesStr;
+ std::vector<std::string> Names = {"foo", "bar", "baz"};
+ collectPGOFuncNameStrings(Names, /*doCompression=*/ true, NamesStr);
+
+ for (int Padding : {0, 1, 2, 3}) {
+ // Join with padding:
+ std::string NamesStrPadded = NamesStr;
+ NamesStrPadded.resize(NamesStr.size() + Padding, '\0');
+
+ // Now decompress the function names:
+ InstrProfSymtab Symtab;
+ Symtab.create(StringRef(NamesStrPadded));
+
+ // Check that we get the function names back:
+ for (auto &Name : Names)
+ ASSERT_EQ(StringRef(Name),
+ Symtab.getFuncName(IndexedInstrProf::ComputeHash(Name)));
}
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D16726.46454.patch
Type: text/x-patch
Size: 3539 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160130/dbff9c84/attachment.bin>
More information about the llvm-commits
mailing list