/*
 * Copyright 2015 Philadelphia authors
 *
 * 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.paritytrading.philadelphia;

import static java.nio.charset.StandardCharsets.*;

import java.io.IOException;
import java.nio.ByteBuffer;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.Level;
import org.openjdk.jmh.annotations.Setup;

public class FIXMessageParserBenchmark extends FIXBenchmark {

    private static final String MESSAGE = "8=FIX.4.2\u00019=74\u000135=D\u000149=initiator\u0001" +
            "56=acceptor\u000134=2\u000111=123\u000121=1\u000155=FOO\u000154=1\u000140=2\u0001" +
            "44=150.25\u000110=075\u0001";

    private ByteBuffer buffer;

    private FIXMessageParser parser;

    @Setup(Level.Iteration)
    public void prepare() {
        buffer = ByteBuffer.allocateDirect(1024);

        buffer.put(MESSAGE.getBytes(US_ASCII));
        buffer.flip();

        FIXConfig config = new FIXConfig.Builder().build();

        parser = new FIXMessageParser(config, listener -> {});
    }

    @Benchmark
    public void baseline() {
    }

    @Benchmark
    public boolean parse() throws IOException {
        boolean result = parser.parse(buffer);

        buffer.flip();

        return result;
    }

}

@@ -1198,63 +1198,324 @@
 ate 
-ByteBuffer buffer;%0A%0A    private FIXMessageParser parser
+static final FIXConfig CHECK_SUM_ENABLED  = new FIXConfig.Builder().build();%0A    private static final FIXConfig CHECK_SUM_DISABLED = new FIXConfig.Builder().setCheckSumEnabled(false).build();%0A%0A    private ByteBuffer buffer;%0A%0A    private FIXMessageParser checkSumEnabled;%0A    private FIXMessageParser checkSumDisabled
 ;%0A%0A 
@@ -1704,69 +1704,93 @@
     
-FIXConfig config = new FIXConfig.Builder().build(
+checkSumEnabled  = new FIXMessageParser(CHECK_SUM_ENABLED,  listener -%3E %7B%7D
 );%0A
-%0A
         
 pars
@@ -1785,22 +1785,32 @@
         
-parser
+checkSumDisabled
  = new F
@@ -1829,14 +1829,26 @@
 ser(
-config
+CHECK_SUM_DISABLED
 , li
@@ -1954,21 +1954,31 @@
 boolean 
-parse
+checkSumEnabled
 () throw
@@ -2022,14 +2022,209 @@
 t = 
-parser
+checkSumEnabled.parse(buffer);%0A%0A        buffer.flip();%0A%0A        return result;%0A    %7D%0A%0A    @Benchmark%0A    public boolean checkSumDisabled() throws IOException %7B%0A        boolean result = checkSumDisabled
 .par

Improve 'FIXMessageParserBenchmark'