You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

AddImageBench.java 2.8KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /* ====================================================================
  2. Licensed to the Apache Software Foundation (ASF) under one or more
  3. contributor license agreements. See the NOTICE file distributed with
  4. this work for additional information regarding copyright ownership.
  5. The ASF licenses this file to You under the Apache License, Version 2.0
  6. (the "License"); you may not use this file except in compliance with
  7. the License. You may obtain a copy of the License at
  8. http://www.apache.org/licenses/LICENSE-2.0
  9. Unless required by applicable law or agreed to in writing, software
  10. distributed under the License is distributed on an "AS IS" BASIS,
  11. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. See the License for the specific language governing permissions and
  13. limitations under the License.
  14. ==================================================================== */
  15. package org.apache.poi.benchmark;
  16. import org.apache.poi.hssf.HSSFTestDataSamples;
  17. import org.apache.poi.ss.usermodel.*;
  18. import org.apache.poi.xssf.usermodel.XSSFWorkbook;
  19. import org.openjdk.jmh.annotations.*;
  20. import org.openjdk.jmh.profile.GCProfiler;
  21. import org.openjdk.jmh.profile.StackProfiler;
  22. import org.openjdk.jmh.runner.Runner;
  23. import org.openjdk.jmh.runner.RunnerException;
  24. import org.openjdk.jmh.runner.options.Options;
  25. import org.openjdk.jmh.runner.options.OptionsBuilder;
  26. import java.util.concurrent.TimeUnit;
  27. @BenchmarkMode(Mode.AverageTime)
  28. @OutputTimeUnit(TimeUnit.MICROSECONDS)
  29. @Warmup(iterations = 10, time = 1, timeUnit = TimeUnit.SECONDS )
  30. @Measurement(iterations = 10, time = 2, timeUnit = TimeUnit.SECONDS)
  31. @State(Scope.Benchmark)
  32. public class AddImageBench {
  33. private Workbook wb;
  34. private CreationHelper helper;
  35. private byte[] bytes;
  36. private Sheet sheet;
  37. @Setup(Level.Iteration)
  38. public void doit() {
  39. wb = new XSSFWorkbook();
  40. helper = wb.getCreationHelper();
  41. //add a picture in this workbook.
  42. bytes = HSSFTestDataSamples.getTestDataFileContent("45829.png");
  43. sheet = wb.createSheet();
  44. }
  45. @Benchmark
  46. public void benchCreatePicture() throws Exception {
  47. Drawing drawing = sheet.createDrawingPatriarch();
  48. ClientAnchor anchor = helper.createClientAnchor();
  49. anchor.setCol1(1);
  50. anchor.setRow1(1);
  51. drawing.createPicture(anchor, wb.addPicture(bytes, Workbook.PICTURE_TYPE_JPEG));
  52. }
  53. public static void main(String[] args) throws RunnerException {
  54. Options opt = new OptionsBuilder()
  55. .include(".*" + AddImageBench.class.getSimpleName() + ".*")
  56. .addProfiler(StackProfiler.class)
  57. .addProfiler(GCProfiler.class)
  58. .forks(1)
  59. .build();
  60. new Runner(opt).run();
  61. }
  62. }