package com.jayjaylab.benchmark;

import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.BenchmarkMode;
import org.openjdk.jmh.annotations.Mode;
import org.openjdk.jmh.annotations.OutputTimeUnit;
import org.openjdk.jmh.infra.Blackhole;
import retrofit2.Call;
import retrofit2.Retrofit;

import java.util.List;
import java.util.concurrent.TimeUnit;

/**
 * Created by jjkim on 2016. 7. 7..
 */
public class AndroidHttpLibraryBenchmark {
    @Benchmark
    @BenchmarkMode(Mode.AverageTime)
    @OutputTimeUnit(TimeUnit.MICROSECONDS)
    public void testRetrofit2(Blackhole blackhole) {
        Retrofit retrofit = new Retrofit.Builder()
                .baseUrl("https://api.github.com/")
                .build();

        GitHubService service = retrofit.create(GitHubService.class);
        Call<List<Repo>> repos = service.listRepos("octocat");
        blackhole.consume(repos);
    }

    @Benchmark
    @BenchmarkMode(Mode.AverageTime)
    @OutputTimeUnit(TimeUnit.MICROSECONDS)
    public void testOkhttp3() {

    }
}

@@ -38,135 +38,206 @@
 ort 
-org.openjdk.jmh.annotations.Benchmark;%0Aimport org.openjdk.jmh.annotations.BenchmarkMode;%0Aimport org.openjdk.jmh.annotations.Mod
+com.fasterxml.jackson.core.type.TypeReference;%0Aimport com.fasterxml.jackson.databind.ObjectMapper;%0Aimport okhttp3.HttpUrl;%0Aimport okhttp3.OkHttpClient;%0Aimport okhttp3.Request;%0Aimport okhttp3.Respons
 e;%0Ai
@@ -270,30 +270,17 @@
 tations.
-OutputTimeUnit
+*
 ;%0Aimport
@@ -362,16 +362,76 @@
 etrofit;
+%0Aimport retrofit2.converter.jackson.JacksonConverterFactory;
 %0A%0Aimport
@@ -574,24 +574,64 @@
 mark %7B%0A    @
+org.openjdk.jmh.annotations.State(Scope.
 Benchmark%0A  
@@ -631,158 +631,295 @@
 mark
+)
 %0A    
-@BenchmarkMode(Mode.AverageTime)%0A    @OutputTimeUnit(TimeUnit.MICROSECONDS)%0A    public void testRetrofit2(Blackhole blackhole) %7B%0A        Retrofit
+public static class State %7B%0A        public Retrofit retrofit;%0A        public OkHttpClient okHttpClient;%0A        public ObjectMapper objectMapper;%0A%0A        @Setup(Level.Trial)%0A        public void setUp() %7B%0A            System.out.println(%22########## setUp() ##########%22);%0A           
  ret
@@ -949,16 +949,20 @@
 ilder()%0A
+    
         
@@ -1025,18 +1025,611 @@
     
-.build();%0A
+    .addConverterFactory(JacksonConverterFactory.create())%0A                    .build();%0A            okHttpClient = new OkHttpClient();%0A            objectMapper = new ObjectMapper();%0A        %7D%0A%0A        @TearDown(Level.Trial)%0A        public void tearDown() %7B%0A            System.out.println(%22########## tearDown() ##########%22);%0A            retrofit = null;%0A            objectMapper = null;%0A            okHttpClient = null;%0A        %7D%0A    %7D%0A%0A    @Benchmark%0A    @BenchmarkMode(%7BMode.SingleShotTime%7D)%0A    @OutputTimeUnit(TimeUnit.MILLISECONDS)%0A    public void testRetrofit2(State state, Blackhole blackhole) %7B
 %0A   
@@ -1657,16 +1657,22 @@
 rvice = 
+state.
 retrofit
@@ -1760,24 +1760,257 @@
 %22octocat%22);%0A
+        List%3CRepo%3E result = null;%0A%0A        try %7B%0A            retrofit2.Response%3CList%3CRepo%3E%3E response = repos.execute();%0A            result = response.body();%0A        %7D catch(Exception e) %7B%0A            e.printStackTrace();%0A        %7D%0A%0A
         blac
@@ -2025,19 +2025,20 @@
 nsume(re
-pos
+sult
 );%0A    %7D
@@ -2077,24 +2077,29 @@
 ode(
+%7B
 Mode.
-Average
+SingleShot
 Time
+%7D
 )%0A  
@@ -2131,11 +2131,11 @@
 t.MI
-CRO
+LLI
 SECO
@@ -2167,20 +2167,795 @@
 Okhttp3(
-) %7B%0A
+State state, Blackhole blackhole) %7B%0A        HttpUrl url = new HttpUrl.Builder()%0A                .scheme(%22https%22)%0A                .host(%22api.github.com%22)%0A                .addPathSegment(%22users%22)%0A                .addPathSegment(%22octocat%22)%0A                .addPathSegment(%22repos%22)%0A                .build();%0A%0A        Request request = new Request.Builder()%0A                .url(url)%0A                .build();%0A        List%3CRepo%3E result = null;%0A%0A        try %7B%0A            Response response = state.okHttpClient.newCall(request).execute();%0A            result = state.objectMapper.readValue(response.body().charStream(),%0A                    new TypeReference%3CList%3CRepo%3E%3E()%7B%7D);%0A        %7D catch (Exception e) %7B%0A            e.printStackTrace();%0A        %7D%0A%0A        blackhole.consume(result);
 %0A    %7D%0A%7D

add benchmark codes