import org.junit.Test;

import java.util.HashSet;
import java.util.Random;
import java.util.Set;

public class TestHashMap {

  public final int SET_SIZE = 10000000;
  public final int DATA_SIZE = 1000000;

  @Test
  public void testHashSetString() throws Exception {
    final Set<String> hashSet = new HashSet<>();
    final Random random = new Random(0xDEADBEEF);
    int matched = 0;

    long startTime = System.nanoTime();

    for (int i = 0; i < SET_SIZE; i++) {
      // input data is String
      String num = Long.toString(random.nextLong());
      hashSet.add(num);
    }

    for (int i = 0; i < DATA_SIZE; i++) {
      // query data is long
      long num = random.nextLong();
      if (hashSet.contains(Long.toString(num))) {
        matched++;
      }
    }

    long endTime = System.nanoTime();
    System.out.println("  HashSet<String>");
    System.out.println("  Elapsed time: " + (endTime - startTime) / 1000000 + " ms");
    System.out.println("  Matched " + matched + " times");
  }

  @Test
  public void testHashSetLongPrimitive() throws Exception {
    final Set<Long> hashSet = new HashSet<>();
    final Random random = new Random(0xDEADBEEF);
    int matched = 0;

    long startTime = System.nanoTime();

    for (int i = 0; i < SET_SIZE; i++) {
      // input data is string
      String num = Long.toString(random.nextLong());
      hashSet.add(Long.parseLong(num));
    }

    for (int i = 0; i < DATA_SIZE; i++) {
      // query data is long
      long num = random.nextLong();
      if (hashSet.contains(num)) {
        matched++;
      }
    }

    long endTime = System.nanoTime();
    System.out.println("  HashSet<long>");
    System.out.println("  Elapsed time: " + (endTime - startTime) / 1000000f + " ms");
    System.out.println("  Matched " + matched + " times");
  }

  @Test
  public void testHashSetLongClass() throws Exception {
    final Set<Long> hashSet = new HashSet<>();
    final Random random = new Random(0xDEADBEEF);
    int matched = 0;

    long startTime = System.nanoTime();

    for (int i = 0; i < SET_SIZE; i++) {
      // input data is string
      String num = Long.toString(random.nextLong());
      hashSet.add(Long.getLong(num));
    }

    for (int i = 0; i < DATA_SIZE; i++) {
      // query data is long
      Long num = random.nextLong();
      if (hashSet.contains(num)) {
        matched++;
      }
    }

    long endTime = System.nanoTime();
    System.out.println("  HashSet<Long>");
    System.out.println("  Elapsed time: " + (endTime - startTime) / 1000000f + " ms");
    System.out.println("  Matched " + matched + " times");
  }
}

@@ -1,12 +1,54 @@
+import org.apache.hadoop.io.LongWritable;%0A
 import org.j
@@ -414,32 +414,75 @@
 int matched = 0;
+%0A    LongWritable num = new LongWritable();
 %0A%0A    long start
@@ -584,35 +584,37 @@
 ng%0A      String 
-num
+input
  = Long.toString
@@ -626,32 +626,93 @@
 om.nextLong());%0A
+      // disable optimizer%0A      if (input.length() %3E 5) %7B%0A  
       hashSet.ad
@@ -717,19 +717,62 @@
 add(
-num
+input
 );%0A
+  
     %7D
+%0A    %7D%0A%0A    random.setSeed(0xDEADBEEF);
 %0A%0A  
@@ -834,38 +834,43 @@
 data is 
-long%0A      long num = 
+LongWritable%0A      num.set(
 random.n
@@ -870,32 +870,33 @@
 andom.nextLong()
+)
 ;%0A      if (hash
@@ -908,20 +908,19 @@
 ontains(
-Long
+num
 .toStrin
@@ -921,19 +921,16 @@
 oString(
-num
 ))) %7B%0A  
@@ -1235,17 +1235,8 @@
 Long
-Primitive
 () t
@@ -1362,32 +1362,75 @@
 int matched = 0;
+%0A    LongWritable num = new LongWritable();
 %0A%0A    long start
@@ -1512,33 +1512,33 @@
 / input data is 
-s
+S
 tring%0A      Stri
@@ -1532,35 +1532,37 @@
 ng%0A      String 
-num
+input
  = Long.toString
@@ -1592,847 +1592,151 @@
     
-hashSet.add(Long.parseLong(num));%0A    %7D%0A%0A    for (int i = 0; i %3C DATA_SIZE; i++) %7B%0A      // query data is long%0A      long num = random.nextLong();%0A      if (hashSet.contains(num)) %7B%0A        matched++;%0A      %7D%0A    %7D%0A%0A    long endTime = System.nanoTime();%0A    System.out.println(%22  HashSet%3Clong%3E%22);%0A    System.out.println(%22  Elapsed time: %22 + (endTime - startTime) / 1000000f + %22 ms%22);%0A    System.out.println(%22  Matched %22 + matched + %22 times%22);%0A  %7D%0A%0A  @Test%0A  public void testHashSetLongClass() throws Exception %7B%0A    final Set%3CLong%3E hashSet = new HashSet%3C%3E();%0A    final Random random = new Random(0xDEADBEEF);%0A    int matched = 0;%0A%0A    long startTime = System.nanoTime();%0A%0A    for (int i = 0; i %3C SET_SIZE; i++) %7B%0A      // input data is string%0A      String num = Long.toString(random.nextLong());%0A      hashSet.add(Long.getLong(num));%0A    %7D
+// disable optimizer%0A      if (input.length() %3E 5) %7B%0A        hashSet.add(Long.parseLong(input));%0A      %7D%0A    %7D%0A%0A    random.setSeed(0xDEADBEEF);
 %0A%0A  
@@ -1802,30 +1802,35 @@
  is 
-long%0A      Long num = 
+LongWritable%0A      num.set(
 rand
@@ -1842,16 +1842,17 @@
 xtLong()
+)
 ;%0A      
@@ -1875,16 +1875,22 @@
 ains(num
+.get()
 )) %7B%0A   

Use query data as LongWritable instead of long