/**
 * Copyright 2015 Netflix, Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.netflix.spectator.perf;

import com.netflix.spectator.api.DefaultRegistry;
import com.netflix.spectator.api.Id;
import com.netflix.spectator.api.Registry;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.Scope;
import org.openjdk.jmh.annotations.State;
import org.openjdk.jmh.annotations.Threads;
import org.openjdk.jmh.infra.Blackhole;
import org.openjdk.jmh.runner.Runner;
import org.openjdk.jmh.runner.RunnerException;
import org.openjdk.jmh.runner.options.Options;
import org.openjdk.jmh.runner.options.OptionsBuilder;

@State(Scope.Thread)
public class Ids {

  private final Registry registry = new DefaultRegistry();

  @Threads(1)
  @Benchmark
  public void justName(Blackhole bh) {
    bh.consume(registry.createId("http.req.complete"));
  }

  @Threads(1)
  @Benchmark
  public void withTags(Blackhole bh) {
    Id id = registry.createId("http.req.complete")
        .withTag("nf.app", "test_app")
        .withTag("nf.cluster", "test_app-main")
        .withTag("nf.asg", "test_app-main-v042")
        .withTag("nf.stack", "main")
        .withTag("nf.ami", "ami-0987654321")
        .withTag("nf.region", "us-east-1")
        .withTag("nf.zone", "us-east-1e")
        .withTag("nf.node", "i-1234567890")
        .withTag("country", "US")
        .withTag("device", "xbox")
        .withTag("status", "200")
        .withTag("client", "ab");
    bh.consume(id);
  }

  public static void main(String[] args) throws RunnerException {
    Options opt = new OptionsBuilder()
        .include(".*")
        .forks(1)
        .build();
    new Runner(opt).run();
  }
}

@@ -1159,16 +1159,65 @@
 ilder;%0A%0A
+import java.util.HashMap;%0Aimport java.util.Map;%0A%0A
 @State(S
@@ -1309,16 +1309,588 @@
 try();%0A%0A
+  private final Map%3CString, String%3E tags = getTags();%0A%0A  private Map%3CString, String%3E getTags() %7B%0A    Map%3CString, String%3E m = new HashMap%3C%3E();%0A    m.put(%22nf.app%22, %22test_app%22);%0A    m.put(%22nf.cluster%22, %22test_app-main%22);%0A    m.put(%22nf.asg%22, %22test_app-main-v042%22);%0A    m.put(%22nf.stack%22, %22main%22);%0A    m.put(%22nf.ami%22, %22ami-0987654321%22);%0A    m.put(%22nf.region%22, %22us-east-1%22);%0A    m.put(%22nf.zone%22, %22us-east-1e%22);%0A    m.put(%22nf.node%22, %22i-1234567890%22);%0A    m.put(%22country%22, %22US%22);%0A    m.put(%22device%22, %22xbox%22);%0A    m.put(%22status%22, %22200%22);%0A    m.put(%22client%22, %22ab%22);%0A    return m;%0A  %7D%0A%0A
   @Threa
@@ -2571,24 +2571,24 @@
 us%22, %22200%22)%0A
-
         .wit
@@ -2634,16 +2634,177 @@
 );%0A  %7D%0A%0A
+  @Threads(1)%0A  @Benchmark%0A  public void withTagsMap(Blackhole bh) %7B%0A    Id id = registry.createId(%22http.req.complete%22).withTags(tags);%0A    bh.consume(id);%0A  %7D%0A%0A
   public

add check for withTags(Map)