forked from Azure/azure-sdk-for-java
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Java] Compute ops/s for each parallel workstream (#5)
* Add comment * Add .vscode to python .gitignore * Compute ops/s for each parallel workstream * Improve status printing Fix bug in opsPerSec calculation
- Loading branch information
1 parent
b915a8c
commit f80c973
Showing
2 changed files
with
80 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
java/azure-perfstress/src/main/java/com/azure/perfstress/SleepTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package com.azure.perfstress; | ||
|
||
import reactor.core.publisher.Mono; | ||
|
||
import java.time.Duration; | ||
import java.util.concurrent.atomic.AtomicInteger; | ||
|
||
public class SleepTest extends PerfStressTest<PerfStressOptions> { | ||
private static final AtomicInteger _instanceCount = new AtomicInteger(); | ||
private final int _secondsPerOperation; | ||
|
||
public SleepTest(PerfStressOptions options) { | ||
super(options); | ||
|
||
int instanceCount = _instanceCount.incrementAndGet(); | ||
_secondsPerOperation = Pow(2, instanceCount); | ||
} | ||
|
||
private static int Pow(int value, int exponent) { | ||
int power = 1; | ||
for (int i=0; i < exponent; i++) { | ||
power *= value; | ||
} | ||
return power; | ||
} | ||
|
||
@Override | ||
public void Run() { | ||
try { | ||
Thread.sleep(_secondsPerOperation * 1000); | ||
} catch (InterruptedException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
|
||
@Override | ||
public Mono<Void> RunAsync() { | ||
return Mono.delay(Duration.ofSeconds(_secondsPerOperation)).then(); | ||
} | ||
} |