Created
December 29, 2016 19:34
-
-
Save mike-ensor/33ed0d2d54d25af10be67276ae6bf896 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@State(Scope.Benchmark) | |
@BenchmarkMode(Mode.AverageTime) | |
@OutputTimeUnit(TimeUnit.MICROSECONDS) | |
public class SerializationBenchmark { | |
private RecipeService service; | |
private Recipe recipe; | |
private byte[] protoRecipe; | |
private String recipeAsJSON; | |
@Setup(Level.Trial) | |
public void setup() { | |
IngredientUsed jalepenoUsed = new IngredientUsed(new Ingredient("Jalepeno", "Spicy Pepper"), MeasurementType.ITEM, 1); | |
IngredientUsed cheeseUsed = new IngredientUsed(new Ingredient("Cheese", "Creamy Cheese"), MeasurementType.OUNCE, 4); | |
recipe = RecipeTestUtil.createRecipe("My Recipe", "Some spicy recipe using a few items", ImmutableList.of(jalepenoUsed, cheeseUsed)); | |
service = new RecipeService(new ObjectMapper()); | |
protoRecipe = service.recipeAsProto(recipe).toByteArray(); | |
recipeAsJSON = service.recipeAsJSON(recipe); | |
} | |
@Benchmark | |
public Messages.Recipe serialize_recipe_object_to_protobuf() { | |
return service.recipeAsProto(recipe); | |
} | |
@Benchmark | |
public String serialize_recipe_object_to_JSON() { | |
return service.recipeAsJSON(recipe); | |
} | |
@Benchmark | |
public Recipe deserialize_protobuf_to_recipe_object() { | |
return service.getRecipe(protoRecipe); | |
} | |
@Benchmark | |
public Recipe deserialize_json_to_recipe_object() { | |
return service.getRecipe(recipeAsJSON); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment