1 Star 0 Fork 3

睿凡/sharecode

forked from dwing/sharecode 
加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
Loom3DeepTest.java 946 Bytes
一键复制 编辑 原始数据 按行查看 历史
dwing 提交于 2024-07-19 16:37 +08:00 . java: update ea-async, async test, loom test
package async;
import jdk.internal.vm.Continuation;
import jdk.internal.vm.ContinuationScope;
// java --add-opens java.base/jdk.internal.vm=ALL-UNNAMED -Xlog:gc=info,gc+heap=info:gc_loom.log:time async.Loom3DeepTest
// 1407 ms, r = 3315906880
public class Loom3DeepTest {
private static final int N = 1000_0000;
private static int s_i;
private static final ContinuationScope cs = new ContinuationScope("VirtualThreads");
private static void f(long v, int a) {
if (v == 0) {
s_i = a;
Continuation.yield(cs);
} else
f(v >> 8, a + (int)(v & 0xff));
}
private static void f() {
for (int i = 0; i < N; i++)
f(0x100_0000_0000_0000L + i, 0);
}
public static void main(String[] args) {
long t = System.nanoTime();
var c = new Continuation(cs, Loom3DeepTest::f);
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/lcpsky/sharecode.git
git@gitee.com:lcpsky/sharecode.git
lcpsky
sharecode
sharecode
main

搜索帮助