use of org.apache.karaf.audit.util.Buffer in project karaf by apache.
the class TestPerf method testGelfTimestamp.
@Test
public void testGelfTimestamp() throws Exception {
long timestamp = System.currentTimeMillis();
int iterations = 1000000;
for (int p = 0; p < 10; p++) {
Buffer buffer = new Buffer(Buffer.Format.Json);
long t0 = measure(() -> {
buffer.clear();
long secs = timestamp / 1000;
int ms = (int) (timestamp - secs * 1000);
buffer.format(secs);
buffer.append('.');
int temp = ms / 100;
buffer.append((char) (temp + '0'));
ms -= 100 * temp;
temp = ms / 10;
buffer.append((char) (temp + '0'));
ms -= 10 * temp;
buffer.append((char) (ms + '0'));
return null;
}, iterations);
System.out.println("t0 = " + t0);
long t1 = measure(() -> {
buffer.clear();
long secs = timestamp / 1000;
int ms = (int) (timestamp - secs * 1000);
buffer.format(Long.toString(secs));
buffer.append('.');
int temp = ms / 100;
buffer.append((char) (temp + '0'));
ms -= 100 * temp;
temp = ms / 10;
buffer.append((char) (temp + '0'));
ms -= 10 * temp;
buffer.append((char) (ms + '0'));
return null;
}, iterations);
System.out.println("t1 = " + t1);
long t2 = measure(() -> {
buffer.clear();
new Formatter(buffer).format("%.3f", ((double) timestamp) / 1000.0);
return null;
}, iterations);
System.out.println("t2 = " + t2);
}
}
use of org.apache.karaf.audit.util.Buffer in project karaf by apache.
the class TestPerf method testFormatString.
@Test
public void testFormatString() throws Exception {
int iterations = 10000000;
for (int i = 0; i < 10; i++) {
final Buffer buffer0 = new Buffer(Buffer.Format.Json);
long t0 = measure(() -> {
buffer0.clear();
buffer0.format("This is \"\n\tquite\n\tq\n\ta\n\tlong\n\tquote.\"\nIndeed !\n");
return null;
}, iterations);
System.out.println("json = " + t0);
final Buffer buffer1 = new Buffer(Buffer.Format.Syslog);
long t1 = measure(() -> {
buffer1.clear();
buffer1.format("This is \"\n\tquite\n\tq\n\ta\n\tlong\n\tquote.\"\nIndeed !\n");
return null;
}, iterations);
System.out.println("syslog = " + t1);
}
}