forked from ricardborgesUdL/POTSimulator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
POTSimulator.java
112 lines (82 loc) · 3.87 KB
/
POTSimulator.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
import Crypto.RSA;
import Helpers.HelperString;
import Helpers.HelperTime;
import POT.Entities.Item;
import POT.Entities.SimulatorSettings;
import java.util.Date;
public class POTSimulator {
private static final String SEPARADOR = "===========================================================";
public static void main(String[] args) {
try {
ExecuteSimulation();
} catch (Exception ex) {
System.out.println("Exception: " + ex.getMessage());
System.out.println("Exception: " + ex.getLocalizedMessage());
}
}
private static void ExecuteSimulation() throws Exception {
Date initDate = new Date();
SimulatorSettings settings = new SimulatorSettings();
String mainTitle = "#################################### POT Simulator v.1.00 ####################################";
System.out.println(mainTitle);
System.out.println();
System.out.println("Settings:");
System.out.println(SEPARADOR);
System.out.println(settings.print());
int aux = Runtime.getRuntime().availableProcessors();
System.out.println("*** Parallelism: " + aux + " ***");
System.out.println();
System.out.println();
System.out.println(SEPARADOR);
System.out.println("--- PRICED OBLIVIOUS TRANSFER");
System.out.println(SEPARADOR);
POTSimulation(settings, 16, 500);
System.out.println();
System.out.println();
System.out.println("Total simulator: " + HelperTime.GetFormattedInterval(initDate));
System.out.println(HelperString.Fill("", mainTitle.length(), '#'));
}
private static void POTSimulation(SimulatorSettings settings, int M, int items) throws Exception {
ManagerPOT manager = getManagerPOT(settings, M, items);
printHeaders(settings, M);
Date ini = new Date();
manager.initialize();
var initCost = new Date().getTime() - ini.getTime();
System.out.println("Init time: " + initCost);
serialSimulation(settings, M, manager);
}
private static void asyncSimulation(SimulatorSettings settings, double M, ManagerPOT manager) {
Date ini;
int simulations;
simulations = settings.MAX_POT_SIMULATIONS;
System.out.println("-> Simulating " + settings.MAX_POT_SIMULATIONS + " executions POT async");
ini = new Date();
manager.simulateAsync(simulations);
double timeAsync = (double) HelperTime.GetMillisecondsSeconds(ini)
/ (double) simulations;
System.out.println("Avg execution: " + timeAsync + " ms.");
System.out.println("Avg/bit: " + (timeAsync / M) + " ms.");
}
private static void serialSimulation(SimulatorSettings settings, double M, ManagerPOT manager) throws Exception {
int simulations = settings.MAX_POT_SIMULATIONS;
System.out.println("-> Simulating " + simulations + " executions POT serial");
var timeSerial = manager.simulateSerial(simulations);
System.out.println(timeSerial);
}
private static void printHeaders(SimulatorSettings settings, int M) {
System.out.println();
System.out.println(HelperString.Fill("", SEPARADOR.length(), '-'));
String title = "--- SIMULATION [m=" + M + " - Items=" + settings.MAX_TICKETS;
System.out.println(title);
System.out.println(HelperString.Fill("", SEPARADOR.length(), '-'));
System.out.println();
}
private static ManagerPOT getManagerPOT(SimulatorSettings settings, int M, int items) {
RSA rsa = new RSA();
settings.MAX_TICKETS = items;
ManagerPOT manager = new ManagerPOT(settings, rsa);
Item.M = M;
Item.MAX_PRICE = (int) (Math.pow(2, M) - 1);
return manager;
}
}