tokuhirom / nanobench

Tiny benchmarking framework for Java 7+
17 stars 3 forks source link

I cannot run HTMLEscapeTest.java in examples/microbenchmarks/ #4

Open shibayu36 opened 7 years ago

shibayu36 commented 7 years ago

I cannot run HTMLEscapeTest.java in examples/microbenchmarks/, because Benchmark interface using lambda is deprecated.

I wrote a test program which can execute.

package me.geso.microbenchmarks;

import org.junit.Test;
import me.geso.nanobench.Benchmark;

import org.apache.commons.lang3.StringEscapeUtils;
import org.springframework.web.util.HtmlUtils;
import com.google.common.html.HtmlEscapers;

public class HTMLEscapeTest {
  @Test
  public void testHTMLEscape() throws Exception {
    new Benchmark(new HTMLEscapeTestBenchmark())
        .runByTime(1).timethese().cmpthese();
  }

  public static class HTMLEscapeTestBenchmark {
    final String src = "<><><><>&&&&;;;;jl2kjlnnfljflksdjfuowu-9urjnl321knl;fu3poifuokbkvnl;uigufjslfjadsipuru1o2krn;lkmfzkjhvojopijkJ:LJKU)!*)($J!KLJOIFHS)JPJ";

    public void benchGuava() {
      HtmlEscapers.htmlEscaper().escape(src);
    }

    public void benchCommons() {
      StringEscapeUtils.escapeHtml4(src);
    }

    public void benchStringReplace() {
      src.replace("&", "&amp;").replace(">", "&gt;")
          .replace("<", "&lt;")
          .replace("'", "&apos;")
          .replaceAll("\"", "&quot;");
    }

    public void benchSpring() {
      HtmlUtils.htmlEscape(src);
    }
  }
}

I tried to send a pull request, but I don't understand how to run this program in maven project under gradle project. So just issued.

tokuhirom commented 7 years ago

It looks good to me :)