forked from peter-lawrey/HugeCollections-OLD
-
Notifications
You must be signed in to change notification settings - Fork 0
/
PingPongPlayerLeft.java
56 lines (43 loc) · 1.65 KB
/
PingPongPlayerLeft.java
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
package net.openhft.collections.fromdocs.com.jpmorgan.pingpong_latency;
import net.openhft.collections.SharedHashMap;
import net.openhft.collections.SharedHashMapBuilder;
import net.openhft.collections.fromdocs.BondVOInterface;
import net.openhft.lang.model.DataValueClasses;
import org.junit.Test;
import java.io.File;
import java.io.IOException;
public class PingPongPlayerLeft {
@Test
public void bondExample() throws IOException, InterruptedException {
SharedHashMap<String, BondVOInterface> shmLeft = new SharedHashMapBuilder()
.generatedValueType(true)
.entrySize(320)
.create(
new File("/dev/shm/BondPortfolioSHM"),
String.class,
BondVOInterface.class
);
BondVOInterface bondOffHeap = DataValueClasses.newDirectReference(BondVOInterface.class);
//BondVOInterface _bondEntryV = shmLeft.acquireUsing("369604103", bondOffHeap);
shmLeft.acquireUsing("369604103", bondOffHeap);
double _couponLeft = 4.0;
double _couponRight = 5.0;
System.out.printf("\n\nPingPongLEFT: Timing 1 x off-heap operations on /dev/shm/RDR_DIM_Mock\n");
bondOffHeap.setCoupon(_couponLeft);
for (int i = 0; i < 500000; i++) {
long _start = System.nanoTime(); //
while (! bondOffHeap.compareAndSwapCoupon(_couponLeft,_couponRight))
;
// while ((_coupon = bondOffHeap.getCoupon()) == 4.0) {
// shmLeft.acquireUsing("369604103", bondOffHeap); //I want to remove this line!!
// ;
// }
long _duration = System.nanoTime() - _start;
System.out.printf("#%d: 1 x _bondEntryV.getCoupon() (last _couponL=[%.2f %%]) in %.1f nanos\n",
i,
bondOffHeap.getCoupon(),
_duration / 2.0);
//Thread.sleep(1);
}
}
}