|
1 | 1 | package com.arangodb.velocypack;
|
2 | 2 |
|
3 | 3 | import com.arangodb.jackson.dataformat.velocypack.VPackMapper;
|
| 4 | +import com.arangodb.velocypack.exception.VPackBuilderException; |
| 5 | +import com.fasterxml.jackson.core.JsonFactory; |
| 6 | +import com.fasterxml.jackson.core.JsonGenerator; |
4 | 7 | import com.fasterxml.jackson.core.JsonProcessingException;
|
5 | 8 | import com.fasterxml.jackson.databind.JsonNode;
|
6 | 9 | import com.fasterxml.jackson.databind.ObjectMapper;
|
|
14 | 17 | import org.openjdk.jmh.runner.options.OptionsBuilder;
|
15 | 18 |
|
16 | 19 | import java.io.IOException;
|
| 20 | +import java.io.StringWriter; |
17 | 21 | import java.nio.file.Files;
|
18 | 22 | import java.nio.file.Path;
|
19 | 23 | import java.nio.file.Paths;
|
@@ -140,4 +144,28 @@ public void toJsonJackson(Data data, Blackhole bh) throws IOException {
|
140 | 144 | bh.consume(str);
|
141 | 145 | }
|
142 | 146 |
|
| 147 | + @Benchmark |
| 148 | + public void toJsonString(Data data, Blackhole bh) { |
| 149 | + String json = VPackParser.toJSONString(data.str); |
| 150 | + bh.consume(json); |
| 151 | + } |
| 152 | + |
| 153 | + @Benchmark |
| 154 | + public void toJsonStringJackson(Data data, Blackhole bh) { |
| 155 | + String json = toJSONStringJackson(data.str); |
| 156 | + bh.consume(json); |
| 157 | + } |
| 158 | + |
| 159 | + private static String toJSONStringJackson(final String text) { |
| 160 | + final StringWriter writer = new StringWriter(); |
| 161 | + try { |
| 162 | + final JsonGenerator generator = new JsonFactory().createGenerator(writer); |
| 163 | + generator.writeString(text); |
| 164 | + generator.close(); |
| 165 | + } catch (final IOException e) { |
| 166 | + throw new VPackBuilderException(e); |
| 167 | + } |
| 168 | + return writer.toString(); |
| 169 | + } |
| 170 | + |
143 | 171 | }
|
0 commit comments