java - 在 Java 中使用 superfasthash
问题描述
我正在测试 superfasthash 和 Java 中使用的默认散列算法之间的速度比较。
但我不确定我是否正确使用了 superfasthash 算法,因为我真的找不到任何关于参数含义的文档。
我在这里得到了算法的 java impl 。
这是我的代码:
public class Main
{
static List<String> dataArray = new ArrayList<>();
public static void main(String[] args) throws IOException
{
writeToArray();
System.out.println("Finished writing to the array.");
//hashing using default java
long startTime = System.nanoTime();
dataArray.stream()
.forEach(s -> s.hashCode());
long endTime = System.nanoTime();
long duration = (endTime - startTime); //divide by 1000000 to get milliseconds.
System.out.println("Finished hashing the file using default java (nanoseconds): " + duration );
//hashing using superfasthash algo
startTime = System.nanoTime();
dataArray.stream()
.forEach(s -> {
SuperFastHash.calculate(s.getBytes(), 1, 1, 1);
});
endTime = System.nanoTime();
duration = (endTime - startTime); //divide by 1000000 to get milliseconds.
System.out.println("Finished hashing superfasthash algo (nanoseconds): " + duration );
}
private static void writeToArray()
{
String abc = "abcdefghijklmnopqrstuvwxyz";
String toHash;
Random r = new Random();
for (int i = 0; i <= 1000000; i++)
{
toHash = "";
for (int ii = 0; ii < 10; ii++)
{
int low = 0;
int high = 26;
int result = r.nextInt(high - low) + low;
toHash = toHash + abc.charAt(result);
}
dataArray.add(toHash);
System.out.println("Writing index = " + i + ". String: " + toHash);
}
}
}
但不确定在使用 SuperFastHash 类中的计算函数时在参数中写什么。