Skip to content

Commit

Permalink
Add a range of marshalling benchmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
tonybaloney committed Aug 29, 2024
1 parent 487ace7 commit 0b124ba
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 1 deletion.
53 changes: 52 additions & 1 deletion src/Profile/MarshallingBenchmarks.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using CSnakes.Runtime;
using BenchmarkDotNet.Attributes;


namespace Profile;

[MarkdownExporter]
Expand All @@ -27,6 +26,58 @@ public void ComplexReturnLazy()
mod!.GenerateDataAny(5, "hello", (3.2, "testinput"), false);
}

[Benchmark]
public void FunctionReturnsList()
{
mod!.GenerateSequence();
}

[Benchmark]
public void FunctionTakesList()
{
List<long> hundredNumbers = [];
for (int i = 0; i < 100; i++)
{
hundredNumbers.Add(i);
}
mod!.ConsumeSequence(hundredNumbers);
}

[Benchmark]
public void FunctionTakesDictionary()
{
Dictionary<string, long> hundredNumbers = [];
for (int i = 0; i < 100; i++)
{
hundredNumbers.Add(i.ToString(), i);
}
mod!.ConsumeDictionary(hundredNumbers);
}

[Benchmark]
public void FunctionReturnsDictionary()
{
mod!.GenerateDictionary();
}

[Benchmark]
public void FunctionReturnsTuple()
{
mod!.GenerateTuple();
}

[Benchmark]
public void FunctionTakesTuple()
{
mod!.ConsumeTuple((5, "hello", 4.2, true));
}

[Benchmark]
public void FunctionTakesValueTypes()
{
mod!.ConsumeValueTypes(5, "hello", 4.2, true);
}

[Benchmark]
public void EmptyFunction()
{
Expand Down
24 changes: 24 additions & 0 deletions src/Profile/marshalling_benchmarks.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,30 @@ def generate_data_any(a: int, b: str, c: tuple[float, str], d: bool) -> Any:
def empty_function() -> None:
pass

def generate_sequence() -> list[int]:
return [i for i in range(100)]

def consume_sequence(sequence: list[int]) -> None:
assert(isinstance(sequence, list) and len(sequence) == 100)

def generate_sequence_any() -> Any:
return [i for i in range(100)]

def consume_dictionary(data: dict[str, int]) -> None:
assert(isinstance(data, dict) and len(data) == 100)

def generate_dictionary() -> dict[str, int]:
return {str(i): i for i in range(100)}

def generate_tuple() -> tuple[int, str, float, bool]:
return (1, "test", 3.2, True)

def consume_tuple(data: tuple[int, str, float, bool]) -> None:
assert(isinstance(data, tuple) and len(data) == 4)

def consume_value_types(a: int, b: str, c: float, d: bool) -> None:
assert(isinstance(a, int) and isinstance(b, str) and isinstance(c, float) and isinstance(d, bool))

if __name__ == "__main__":
# Start timer
import time
Expand Down

0 comments on commit 0b124ba

Please sign in to comment.