diff options
| author | Cliff Click <cliffc@acm.org> | 2026-10-28 16:14:30 -0700 |
|---|---|---|
| committer | Cliff Click <cliffc@acm.org> | 2026-10-28 16:14:30 -0700 |
| commit | 3df967056bf48bd9f87900f3a1ad9af2aedce948 (patch) | |
| tree | fdbdac5e5919deabb08d353147da32b7ccb741d8 /chapter17a/src/test/java/com/seaofnodes | |
| parent | 50924bbe7cfeecfe7aec1885dae9bbda0013ac1b (diff) | |
| download | Simple-3df967056bf48bd9f87900f3a1ad9af2aedce948.tar.gz Simple-3df967056bf48bd9f87900f3a1ad9af2aedce948.zip | |
Backport some minor speedups
Diffstat (limited to 'chapter17a/src/test/java/com/seaofnodes')
| -rw-r--r-- | chapter17a/src/test/java/com/seaofnodes/simple/SchedulingScratchTest.java | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/chapter17a/src/test/java/com/seaofnodes/simple/SchedulingScratchTest.java b/chapter17a/src/test/java/com/seaofnodes/simple/SchedulingScratchTest.java new file mode 100644 index 00000000..b3984f15 --- /dev/null +++ b/chapter17a/src/test/java/com/seaofnodes/simple/SchedulingScratchTest.java @@ -0,0 +1,31 @@ +package com.seaofnodes.simple; + +import com.seaofnodes.simple.evaluator.Evaluator; +import com.seaofnodes.simple.node.StopNode; +import org.junit.Test; +import static org.junit.Assert.assertEquals; + +public class SchedulingScratchTest { + @Test public void testScratchAcrossCompilations() { + String src = """ + int[] xs = new int[2]; + xs[0] = arg; + int sum = 0; + int i = 0; + while( i<5 ) { + int old = xs[arg&1]; + xs[0] = i; + sum = sum + old; + i = i + 1; + } + return sum; + """; + // Each fresh compilation reuses node IDs and the scheduler's scratch. + for( int round=0; round<3; round++ ) { + StopNode stop = new Parser(src).parse().iterate(); + assertEquals(6L,Evaluator.evaluate(stop,0)); + assertEquals(0L,Evaluator.evaluate(stop,1)); + assertEquals(8L,Evaluator.evaluate(stop,2)); + } + } +} |
