use of org.polymap.core.runtime.Timer in project polymap4-core by Polymap4.
the class PredefinedColorMap method minMax3.
/**
* @return double[] {min, max, novalue}
*/
protected double[] minMax3(GridCoverage2D grid, IProgressMonitor monitor) {
@SuppressWarnings("hiding") double // see OmsRasterReader
novalue = -9999.0;
double min = Double.POSITIVE_INFINITY;
double max = Double.NEGATIVE_INFINITY;
RenderedImage renderedImage = grid.getRenderedImage();
monitor.beginTask("calculating min/max", renderedImage.getHeight());
RectIter iter = RectIterFactory.create(renderedImage, null);
Timer timer = new Timer();
int sampleCount = 0;
do {
do {
double value = iter.getSampleDouble();
if (value == novalue) {
continue;
}
if (value < novalue) {
throw new IllegalStateException("XXX value < novalue : " + value);
}
if (value < min) {
min = value;
}
if (value > max) {
max = value;
}
sampleCount++;
} while (!iter.nextPixelDone());
iter.startPixels();
monitor.worked(1);
// monitor.subTask( String.valueOf( sampleCount ) );
} while (// http://github.com/Polymap4/polymap4-core/issues/108 will be better/faster
!iter.nextLineDone() && timer.elapsedTime() < 5000);
monitor.done();
log.info("minMax(): " + sampleCount + " samples in " + timer.elapsedTime() + "ms");
// XXX check novalue
return new double[] { min, max, novalue };
}
use of org.polymap.core.runtime.Timer in project polymap4-core by Polymap4.
the class PredefinedColorMapEditor method minMax.
protected double[] minMax(GridCoverage2D grid) {
GridGeometry2D geometry = grid.getGridGeometry();
GridEnvelope gridRange = geometry.getGridRange();
int w = gridRange.getHigh(0);
int h = gridRange.getHigh(1);
Timer timer = new Timer();
Random random = new Random();
double min = Double.MAX_VALUE;
double max = Double.MIN_VALUE;
double[] values = new double[1];
for (int i = 0; i < 10000 || timer.elapsedTime() < 1000; i++) {
grid.evaluate(new GridCoordinates2D(random.nextInt(w), random.nextInt(h)), values);
min = values[0] < min ? values[0] : min;
max = values[0] > max ? values[0] : max;
}
return new double[] { min, max };
}
use of org.polymap.core.runtime.Timer in project polymap4-core by Polymap4.
the class PerformanceCacheTest method tstLoader.
public void tstLoader() throws Exception {
Timer timer = new Timer();
int count = 0;
while (timer.elapsedTime() < 10000) {
log.println("adding 1000 to " + cache.size());
for (int i = 0; i < 1000; i++) {
cache.get(new Object(), key -> new byte[1024]);
count++;
}
Thread.sleep(100);
}
long time = timer.elapsedTime();
log.println("Loops: " + count + " in " + time + "ms -> " + (1000f * count / time) + "/s");
}
use of org.polymap.core.runtime.Timer in project polymap4-core by Polymap4.
the class PerformanceCacheTest method tstRandom.
public void tstRandom() throws Exception {
Timer timer = new Timer();
int count = 0;
Random random = new Random();
ByteArrayLoader loader = new ByteArrayLoader();
while (timer.elapsedTime() < 5000) {
log.println("adding 1000 to " + cache.size());
for (int i = 0; i < 10000; i++) {
Integer key = new Integer((int) (Math.abs(random.nextGaussian()) * 400000));
cache.get(key, loader);
count++;
}
}
long time = timer.elapsedTime();
log.println("Loops: " + count + " in " + time + "ms -> " + (1000f * count / time) + "/s");
}
use of org.polymap.core.runtime.Timer in project polymap4-core by Polymap4.
the class Cache304 method updateLayer.
public void updateLayer(String layer, Geometry changed) {
// flush queue
if (!updateQueue.isEmpty()) {
log.warn("Queue is not empty before updateLayer()!");
}
// remove all tiles for layer
IRecordStore.Updater tx = null;
try {
lock.writeLock().tryLock(3, TimeUnit.SECONDS);
SimpleQuery query = new SimpleQuery();
query.eq(CachedTile.TYPE.layerId.name(), layer);
query.setMaxResults(1000000);
ResultSet resultSet = store.find(query);
log.debug("Removing tiles: " + resultSet.count());
Timer timer = new Timer();
tx = store.prepareUpdate();
for (IRecordState record : resultSet) {
deleteTile(record, tx);
}
tx.apply(true);
log.debug("done. (" + timer.elapsedTime() + "ms)");
} catch (Exception e) {
if (tx != null) {
tx.discard();
}
} finally {
lock.writeLock().unlock();
}
}
Aggregations