File tree Expand file tree Collapse file tree 3 files changed +13
-6
lines changed Expand file tree Collapse file tree 3 files changed +13
-6
lines changed Original file line number Diff line number Diff line change @@ -10,8 +10,8 @@ public static void main(String[] args) {
1010 SynchroStackFast .class
1111 };
1212
13- int threadsPerMethod = 2 ; // threads per method
14- int itersPerMethod = 5 ; // iterations per method
13+ int threadsPerMethod = 24 ; // threads per method
14+ int itersPerMethod = 1000 ; // iterations per method
1515
1616 // logs file path
1717 String logsPath = "src/labs/sem1/lab10/results/%s.csv" ;
@@ -46,12 +46,12 @@ public static void main(String[] args) {
4646 }
4747 },
4848 () -> { // equals (read operation, light)
49- for (int i = 0 ; i < itersPerMethod ; i ++) {
49+ for (int i = 0 ; i < itersPerMethod * 20 ; i ++) {
5050 stack .equals (stack );
5151 }
5252 },
5353 () -> { // toString (read operation, heavy)
54- for (int i = 0 ; i < itersPerMethod ; i ++) {
54+ for (int i = 0 ; i < itersPerMethod / 5 ; i ++) {
5555 stack .toString ();
5656 }
5757 }
@@ -106,3 +106,10 @@ public static void main(String[] args) {
106106 }
107107 }
108108}
109+
110+ // example output:
111+
112+ // Benchmarking: Stack - took 669 ms
113+ // Benchmarking: DebugStack - took 3725 ms
114+ // Benchmarking: SynchroStack - took 3845 ms
115+ // Benchmarking: SynchroStackFast - took 2180 ms
Original file line number Diff line number Diff line change 22
33// с этим классом одновременно может работать один поток (для всех методов)
44
5- public class SynchroStack extends DebugStack {
5+ public class SynchroStack extends Stack {
66 // change this to extends DebugStack / Stack to enable / disable debug
77
88 public synchronized void push (int i ) {
Original file line number Diff line number Diff line change 44// (push и pop) и несколько читающих (equals и toString)
55// для этого есть два объекта-монитора: для записи и для чтения
66
7- public class SynchroStackFast extends DebugStack {
7+ public class SynchroStackFast extends Stack {
88 // change this to extends DebugStack / Stack to enable / disable debug
99
1010 Object readLock = new Object ();
You can’t perform that action at this time.
0 commit comments