<commit_before>package com.eclipsesource.json.performancetest.jsonrunners;

import java.io.Reader;
import java.io.Writer;

import org.codehaus.jackson.JsonFactory;
import org.codehaus.jackson.JsonParser;
import org.codehaus.jackson.map.ObjectMapper;


public class JacksonRunner implements JsonRunner {

  private final JsonFactory factory;

  public JacksonRunner() {
    factory = new JsonFactory();
  }

  @Override
  public Object readFromString( String string ) throws Exception {
    ObjectMapper mapper = new ObjectMapper();
    JsonParser parser = factory.createJsonParser( string );
    try {
      return mapper.readTree( parser );
    } finally {
      parser.close();
    }
  }

  @Override
  public Object readFromReader( Reader reader ) throws Exception {
    ObjectMapper mapper = new ObjectMapper();
    JsonParser parser = factory.createJsonParser( reader );
    try {
      return mapper.readTree( parser );
    } finally {
      parser.close();
    }
  }

  @Override
  public String writeToString( Object model ) throws Exception {
    ObjectMapper mapper = new ObjectMapper();
    return mapper.writeValueAsString( model );
  }

  @Override
  public void writeToWriter( Object model, Writer writer ) throws Exception {
    ObjectMapper mapper = new ObjectMapper();
    mapper.writeValue( writer, model );
  }
<commit_msg>Reuse Jackson object mapper in benchmarks<commit_after>package com.eclipsesource.json.performancetest.jsonrunners;

import java.io.Reader;
import java.io.Writer;

import org.codehaus.jackson.JsonFactory;
import org.codehaus.jackson.JsonParser;
import org.codehaus.jackson.map.ObjectMapper;


public class JacksonRunner implements JsonRunner {

  private final JsonFactory factory;
  private final ObjectMapper mapper;

  public JacksonRunner() {
    // Reuse factory and object mapper to improve performance
    // See http://wiki.fasterxml.com/JacksonBestPracticesPerformance
    factory = new JsonFactory();
    mapper = new ObjectMapper();
  }

  @Override
  public Object readFromString( String string ) throws Exception {
    JsonParser parser = factory.createJsonParser( string );
    try {
      return mapper.readTree( parser );
    } finally {
      parser.close();
    }
  }

  @Override
  public Object readFromReader( Reader reader ) throws Exception {
    JsonParser parser = factory.createJsonParser( reader );
    try {
      return mapper.readTree( parser );
    } finally {
      parser.close();
    }
  }

  @Override
  public String writeToString( Object model ) throws Exception {
    return mapper.writeValueAsString( model );
  }

  @Override
  public void writeToWriter( Object model, Writer writer ) throws Exception {
    mapper.writeValue( writer, model );
  }

{'fraction_non_alphanumeric': 0.08537925980212532, 'fraction_numerical': 0.0, 'mean_word_length': 3.634974533106961, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 1}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '383069', 'n_tokens_mistral': 764, 'n_tokens_neox': 732, 'n_words': 210}