嗨,我有一个关于 std::hash 的问题,如果我有 2 个大字符串进行比较,我愿意接受 std::hash 在大多数情况下比较相等,是否更符合性能,而不是直接执行以下操作字符串比较?还要考虑这将在一个循环中读取文件,因此它将被执行多次,这是对大文件的关注。
std::string largeString1; // large but not huge meaning a line of text like up to lets say 500 chars
std::string largeString2;
// is this better than then next block in terms of performance and if so by how much?
if ( std::hash<std::string>(largeString1) == std::hash<std::string>(largeString2) )
{
// true logic
}
// is this a lot slower than the previous
if ( largeString1 == largeString2 )
{
// true logic
}