Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 45 additions & 3 deletions src/mono/sample/wasm/browser-bench/Exceptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class ExceptionsTask : BenchTask
public ExceptionsTask()
{
measurements = new Measurement[] {
new NoExceptionHandling(),
new TryCatch(),
new TryCatchThrow(),
new TryCatchFilter(),
Expand All @@ -41,10 +42,32 @@ public abstract class ExcMeasurement : BenchTask.Measurement
public override int InitialSamples => 10000;
}

class NoExceptionHandling : ExcMeasurement
{
public override string Name => "NoExceptionHandling";
public override int InitialSamples => 1000000;
bool increaseCounter = false;
int unusedCounter;

public override void RunStep()
{
DoNothing();
}

[MethodImpl(MethodImplOptions.NoInlining)]
void DoNothing ()
{
if (increaseCounter)
unusedCounter++;
}
}

class TryCatch : ExcMeasurement
{
public override string Name => "TryCatch";
public override int InitialSamples => 1000000;
bool doThrow = false;

public override void RunStep()
{
try
Expand All @@ -58,12 +81,16 @@ public override void RunStep()
[MethodImpl(MethodImplOptions.NoInlining)]
void DoNothing ()
{
if (doThrow)
throw new Exception ("Reached DoThrow and throwed");
}
}

class TryCatchThrow : ExcMeasurement
{
public override string Name => "TryCatchThrow";
bool doThrow = true;

public override void RunStep()
{
try
Expand All @@ -78,13 +105,16 @@ public override void RunStep()
[MethodImpl(MethodImplOptions.NoInlining)]
void DoThrow()
{
throw new System.Exception("Reached DoThrow and throwed");
if (doThrow)
throw new System.Exception("Reached DoThrow and throwed");
}
}

class TryCatchFilter : ExcMeasurement
{
public override string Name => "TryCatchFilter";
bool doThrow = false;

public override void RunStep()
{
try
Expand All @@ -99,12 +129,16 @@ public override void RunStep()
[MethodImpl(MethodImplOptions.NoInlining)]
void DoNothing()
{
if (doThrow)
throw new Exception("Reached DoThrow and throwed");
}
}

class TryCatchFilterInline : ExcMeasurement
{
public override string Name => "TryCatchFilterInline";
bool doThrow = false;

public override void RunStep()
{
try
Expand All @@ -119,12 +153,16 @@ public override void RunStep()
[MethodImpl(MethodImplOptions.AggressiveInlining)]
void DoNothing()
{
if (doThrow)
throw new Exception("Reached DoThrow and throwed");
}
}

class TryCatchFilterThrow : ExcMeasurement
{
public override string Name => "TryCatchFilterThrow";
bool doThrow = true;

public override void RunStep()
{
try
Expand All @@ -142,13 +180,16 @@ public override void RunStep()
[MethodImpl(MethodImplOptions.NoInlining)]
void DoThrow()
{
throw new System.Exception("Reached DoThrow and throwed");
if (doThrow)
throw new System.Exception("Reached DoThrow and throwed");
}
}

class TryCatchFilterThrowApplies : ExcMeasurement
{
public override string Name => "TryCatchFilterThrowApplies";
bool doThrow = true;

public override void RunStep()
{
try
Expand All @@ -163,7 +204,8 @@ public override void RunStep()
[MethodImpl(MethodImplOptions.NoInlining)]
void DoThrow()
{
throw new System.Exception("Reached DoThrow and throwed");
if (doThrow)
throw new System.Exception("Reached DoThrow and throwed");
}
}
}
Expand Down