forked from Azure/azure-sdk-for-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Compute ops/s for each parallel workstream (Azure#4)
- More accurate than averaging time
- Loading branch information
1 parent
9a29639
commit b915a8c
Showing
4 changed files
with
76 additions
and
31 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
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
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,38 @@ | ||
using System; | ||
using System.Numerics; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
namespace Azure.Test.PerfStress | ||
{ | ||
// Used for verifying the perf framework correctly computes average throughput across parallel tests of different speed | ||
public class SleepTest : PerfStressTest<PerfStressOptions> | ||
{ | ||
private static int _instanceCount = 0; | ||
private readonly int _secondsPerOperation; | ||
|
||
public SleepTest(PerfStressOptions options) : base(options) { | ||
// Each instance of this test completes operations at a different rate, to allow for testing scenarios where | ||
// some instances are still waiting when time expires. The first instance completes in 2 seconds per operation, | ||
// the second instance in 4 seconds, the third instance in 8 seconds, and so on. | ||
|
||
var instanceCount = Interlocked.Increment(ref _instanceCount); | ||
_secondsPerOperation = Pow(2, instanceCount); | ||
} | ||
|
||
private static int Pow(int value, int exponent) | ||
{ | ||
return (int)BigInteger.Pow(new BigInteger(value), exponent); | ||
} | ||
|
||
public override void Run(CancellationToken cancellationToken) | ||
{ | ||
Thread.Sleep(TimeSpan.FromSeconds(_secondsPerOperation)); | ||
} | ||
|
||
public override Task RunAsync(CancellationToken cancellationToken) | ||
{ | ||
return Task.Delay(TimeSpan.FromSeconds(_secondsPerOperation), cancellationToken); | ||
} | ||
} | ||
} |
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