1 Star 0 Fork 3

artshell/sharecode

forked from dwing/sharecode 
加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
Loom3Test.java 1.06 KB
一键复制 编辑 原始数据 按行查看 历史
dwing 提交于 2022-06-27 17:38 +08:00 . java: add Loom4Test, AsyncDeepTest, Loom3DeepTest
package async;
import jdk.internal.vm.Continuation;
import jdk.internal.vm.ContinuationScope;
// 1249 ms, r = 4995000000 java --enable-preview --add-opens java.base/jdk.internal.vm=ALL-UNNAMED -Xlog:gc=info,gc+heap=info:gc_loom.log:time async.Loom3Test
public class Loom3Test {
private static final int N1 = 100;
private static final int N2 = 100;
private static final int N3 = 1000;
private static final int N = N1 * N2 * N3;
private static int s_i;
private static final ContinuationScope cs = new ContinuationScope("VirtualThreads");
private static void f3() {
for (int i = 0; i < N3; i++) {
s_i = i;
Continuation.yield(cs);
}
}
private static void f2() {
for (int i = 0; i < N2; i++)
f3();
}
private static void f1() {
for (int i = 0; i < N1; i++)
f2();
}
public static void main(String[] args) throws Exception {
long t = System.nanoTime();
var c = new Continuation(cs, Loom3Test::f1);
long r = 0;
for (int i = 0; i < N; ++i) {
c.run();
r += s_i;
}
System.out.println((System.nanoTime() - t) / 1_000_000 + " ms, r = " + r);
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
其他
1
https://gitee.com/artshell/sharecode.git
git@gitee.com:artshell/sharecode.git
artshell
sharecode
sharecode
main

搜索帮助