forked from jooby-project/jooby
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBenchApp.java
More file actions
63 lines (49 loc) · 1.54 KB
/
Copy pathBenchApp.java
File metadata and controls
63 lines (49 loc) · 1.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/**
* Jooby https://jooby.io
* Apache License Version 2.0 https://jooby.io/LICENSE.txt
* Copyright 2014 Edgar Espina
*/
package examples;
import io.jooby.ExecutionMode;
import io.jooby.Jooby;
import java.io.UnsupportedEncodingException;
import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets;
public class BenchApp extends Jooby {
private static final String MESSAGE = "Hello, World!";
private static final byte[] MESSAGE_BYTE = MESSAGE.getBytes(StandardCharsets.UTF_8);
private static final ByteBuffer MESSAGE_BUFFER = ByteBuffer.allocateDirect(MESSAGE.length());
static class Message {
public final String message;
public Message(String message) {
this.message = message;
}
}
static {
try {
MESSAGE_BUFFER.put(MESSAGE.getBytes("US-ASCII")).flip();
} catch (UnsupportedEncodingException e) {
throw new IllegalStateException(e);
}
}
{
get("/gc", ctx -> {
long before = Runtime.getRuntime().freeMemory();
System.gc();
long after = Runtime.getRuntime().freeMemory();
return before + ":" + after + "(" + (before - after) + ")";
});
get("/plaintext", ctx -> {
return ctx.send(MESSAGE_BYTE);
});
get("/", ctx -> {
System.out.println(ctx.getRequestPath());
return ctx.send(MESSAGE_BYTE);
});
get("/json", ctx -> Thread.currentThread().getName());
get("/fortune", ctx -> Thread.currentThread().getName());
}
public static void main(String[] args) {
runApp(args, ExecutionMode.EVENT_LOOP, BenchApp::new);
}
}