Commit 562ed4da authored by Matija Obreza's avatar Matija Obreza
Browse files

Performance test

parent fb438f43
......@@ -29,7 +29,7 @@ import com.jayway.jsonpath.spi.mapper.MappingProvider;
/**
* The Class JsonPathTest.
*/
public class JsonPathTest {
public abstract class JsonPathTest {
/**
* Instantiates a new json path test.
......
/*
* Copyright 2016 Global Crop Diversity Trust, www.croptrust.org
*
* 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 org.croptrust.excel.templates;
import java.io.IOException;
import org.apache.commons.lang.time.StopWatch;
import org.apache.poi.EncryptedDocumentException;
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.ss.usermodel.WorkbookFactory;
import org.croptrust.excel.templates.impl.ExcelToJSONImpl;
import org.croptrust.excel.templates.impl.ExcelToMapsJSONImpl;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class PerformanceTest extends JsonPathTest {
private final static Logger LOG = LoggerFactory.getLogger(PerformanceTest.class);
private ExcelToJSON[] excelToJsonServices = new ExcelToJSON[] { new ExcelToJSONImpl(), new ExcelToMapsJSONImpl() };
@Test
public void testPerformance() throws IOException, EncryptedDocumentException, InvalidFormatException {
String[][] columnMappings = new String[][] {
new String[] { "timestamp" }, new String[] { "timestamp", "traveller.fullName", "", "traveller.organization" },
new String[] { "timestamp", "itinerary[0].origin", null, "itinerary[1].destination" },
new String[] { "a", "b", "c", "d", "e", "f", "g", "h" },
};
StopWatch stopWatch = new StopWatch();
String defaults="{\"this\":[\"is a\", 1], \"test\":{\"bar\":{\"foo\":[1]}}}";
try (Workbook wb = WorkbookFactory.create(BasicExcelTest.PARTICIPANTS_XSLX)) {
Sheet sheet = wb.getSheetAt(0);
int numberOfRepeats1 = LOG.isDebugEnabled() ? 100 : 20;
while (numberOfRepeats1-- > 0) {
for (ExcelToJSON excelToJson : excelToJsonServices) {
stopWatch.reset();
stopWatch.start();
int numberOfRepeats2 = LOG.isTraceEnabled() ? 1000 : 100;
while (numberOfRepeats2-- > 0) {
for (String[] columnMapping : columnMappings) {
excelToJson.readAsJson(sheet, columnMapping, defaults, true, true);
}
}
stopWatch.stop();
LOG.info("Time taken service={} \ttime={}", excelToJson.getClass().getSimpleName(), stopWatch.getTime());
}
}
}
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment