use of org.polymap.core.runtime.Timer in project polymap4-core by Polymap4.
the class ImageEncodeProcessor method encodeImageResponse.
@Consumes(ImageResponse.class)
@Produces({ EncodedImageResponse.class, EndOfProcessing.class })
public void encodeImageResponse(ImageResponse response, ProcessorContext context) throws Exception {
Timer timer = new Timer();
// chunked reponse output stream
ChunkedResponseOutputStream out = new ChunkedResponseOutputStream(context) {
protected ProcessorResponse createResponse(byte[] buf, int buflen) {
// log.debug( "sending: buflen= " + buflen );
return new EncodedImageResponse(buf, buflen);
}
};
// load image data
// new javax.swing.ImageIcon( image ).getImage();
String format = (String) context.get("format");
if ("image/jpeg".equals(format)) {
imageioEncodeJPEG(response.getImage(), out);
} else {
opEncodePNG(response.getImage(), out);
}
log.debug("encode: ready. (" + timer.elapsedTime() + "ms)");
out.flush();
context.sendResponse(ProcessorResponse.EOP);
log.debug("...all data sent. (" + out.getTotalSent() + " bytes " + format + ")");
}
use of org.polymap.core.runtime.Timer in project polymap4-core by Polymap4.
the class LuceneRecordQuery method execute.
public ResultSet execute() throws IOException {
Timer timer = new Timer();
// Lucene does not have a firstResult feature
int requestedResults = getMaxResults() + getFirstResult();
return store.readLocked(() -> {
String sortKey = getSortKey();
if (sortKey != null) {
int sortType = SortField.STRING;
if (getSortType() == String.class) {
sortType = SortField.STRING;
} else if (getSortType() == Integer.class) {
sortType = SortField.INT;
} else if (getSortType() == Long.class) {
sortType = SortField.LONG;
} else if (getSortType() == Float.class) {
sortType = SortField.FLOAT;
} else if (getSortType() == Double.class) {
sortType = SortField.DOUBLE;
} else if (getSortType() == Date.class) {
sortType = SortField.LONG;
sortKey = sortKey + DateValueCoder.SUFFIX;
}
Sort sort = new Sort(new SortField(sortKey, sortType, getSortOrder() == DESC));
TopDocs topDocs = store.searcher.search(luceneQuery, requestedResults, sort);
logResult(topDocs.scoreDocs.length, timer);
return new LuceneResultSet(topDocs.scoreDocs);
} else {
TopDocs topDocs = store.searcher.search(luceneQuery, requestedResults);
logResult(topDocs.scoreDocs.length, timer);
return new LuceneResultSet(topDocs.scoreDocs);
}
});
}
use of org.polymap.core.runtime.Timer in project polymap4-core by Polymap4.
the class AbstractRecordStoreTest method createRecords.
// public void tstThreaded() throws Exception {
// final int loops = 250;
// final int threads = 4;
// createRecords( loops*threads );
//
// List<Future> results = new ArrayList();
// for (int i=0; i<threads; i++) {
// results.add( Polymap.executorService().submit( new Callable() {
// public Object call() throws Exception {
// // readRecords( loops );
// queryRecords( loops );
// return new Object();
// }
// } ) );
// }
// // wait for results
// for (Future result : results) {
// result.get();
// }
// }
protected void createRecords(int loops) throws Exception {
start = System.currentTimeMillis();
final Timer timer = new Timer();
Updater updater = store.prepareUpdate();
try {
for (int i = 0; i < loops; i++) {
TestRecord record = new TestRecord(store.newRecord());
record.payload.put("LuceneRecordStore store = new LuceneRecordStore( new File LuceneRecordStore store = new LuceneRecordStore( new File LuceneRecordStore store = new LuceneRecordStore( new File");
record.type.put("2");
record.count.put(i);
updater.store(record.state());
}
updater.apply();
} catch (Exception e) {
updater.discard();
throw e;
}
log.info("Records created: " + loops + " in " + timer.elapsedTime() + "ms -> " + (double) timer.elapsedTime() / loops + "ms/loop");
}
use of org.polymap.core.runtime.Timer in project polymap4-core by Polymap4.
the class StyleRepository method toSLD.
protected String toSLD(org.geotools.styling.Style style) {
Timer timer = new Timer();
try {
SLDTransformer styleTransform = new SLDTransformer();
styleTransform.setIndentation(4);
styleTransform.setOmitXMLDeclaration(false);
return styleTransform.transform(style);
} catch (TransformerException e) {
throw new RuntimeException("Unable to transform style.", e);
} finally {
log.info("Style to SLD: " + timer.elapsedTime() + "ms.");
}
}
use of org.polymap.core.runtime.Timer in project polymap4-core by Polymap4.
the class Sequence method main.
// test ***********************************************
/**
* @throws Exception
* @throws ExecutionException
*/
public static void main(String[] args) throws Exception {
int loops = 100000;
int elements = 1000;
Integer[] numbers = new Integer[elements];
Arrays.fill(numbers, 1);
//
Timer timer = new Timer();
int result = 0;
for (int i = 0; i < loops; i++) {
result += Sequence.of(numbers).filter(elm -> nonzero(elm)).filter(elm -> elm < 3).count();
}
System.out.println(result + " - loops: " + loops + "x" + elements + " in " + timer.elapsedTime() + "ms");
//
timer = new Timer();
result = 0;
for (int i = 0; i < loops; i++) {
result += Arrays.asList(numbers).stream().filter(elm -> nonzero(elm)).filter(elm -> elm < 3).count();
}
System.out.println(result + " - loops: " + loops + "x" + elements + " in " + timer.elapsedTime() + "ms");
//
timer = new Timer();
result = 0;
for (int i = 0; i < loops; i++) {
int count = 0;
for (Integer elm : numbers) {
if (nonzero(elm)) {
if (elm < 3) {
count++;
}
}
}
result += count;
}
System.out.println(result + " - loops: " + loops + "x" + elements + " in " + timer.elapsedTime() + "ms");
}
Aggregations