Skip to content
Open
Show file tree
Hide file tree
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
68 changes: 68 additions & 0 deletions benchmark/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
using System;
using System.Diagnostics;
using System.Collections.Generic;

public class Program
{
public static void Main()
{
var dict = new Dictionary<string, object>();
for (int i = 0; i < 50; i++)
{
dict.Add($"key_{i}", $"value_{i}");
}

// warmup
OldWay(dict);
NewWay(dict);

var sw = new Stopwatch();

sw.Start();
for(int i = 0; i < 100000; i++) OldWay(dict);
sw.Stop();
Console.WriteLine($"Old way: {sw.ElapsedMilliseconds} ms");

sw.Restart();
for(int i = 0; i < 100000; i++) NewWay(dict);
sw.Stop();
Console.WriteLine($"New way: {sw.ElapsedMilliseconds} ms");
}

public static string OldWay(IDictionary<string, object> dict)
{
string result = string.Empty;
foreach (var item in dict)
{
object value = item.Value;
if (value == null) continue;

value = $"\\\"{value}\\\"";
string key = $"\\\"{item.Key}\\\"";
if (string.IsNullOrEmpty(result))
{
result = $"{key}: {value}";
}
else
{
result = result + ", " + key + ": " + value;
}
}
return "\"{" + result + "}\"";
}

public static string NewWay(IDictionary<string, object> dict)
{
var elements = new List<string>(dict.Count);
foreach (var item in dict)
{
object value = item.Value;
if (value == null) continue;

value = $"\\\"{value}\\\"";
string key = $"\\\"{item.Key}\\\"";
elements.Add($"{key}: {value}");
}
return "\"{" + string.Join(", ", elements) + "}\"";
}
}
10 changes: 10 additions & 0 deletions benchmark/benchmark.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net10.0</TargetFramework>
Copy link

Copilot AI Mar 22, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The benchmark project targets net10.0, but this repo’s CI/tooling is configured for older SDKs (unit-test workflow installs .NET 8.0.x, release workflow installs .NET 5.0.x). Even though the benchmark isn’t in Appium.Net.sln today, keeping it on a newer TFM can make it difficult for contributors to build/run without extra SDK installs. Consider targeting net8.0 (or otherwise aligning the benchmark TFM with the repo’s supported SDK range).

Suggested change
<TargetFramework>net10.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>

Copilot uses AI. Check for mistakes.
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

</Project>
58 changes: 26 additions & 32 deletions src/Appium.Net/Appium/Service/Options/OptionCollector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,53 +78,47 @@ public OptionCollector AddCapabilities(AppiumOptions options)

private string ParseCapabilitiesIfWindows()
{
string result = string.Empty;
if (options == null)
{
return "\"{}\"";
}

if (options != null)
IDictionary<string, object> capabilitiesDictionary = options.ToDictionary();
List<string> result = new List<string>(capabilitiesDictionary.Count);

foreach (var item in capabilitiesDictionary)
{
IDictionary<string, object> capabilitiesDictionary = options.ToDictionary();
object value = item.Value;

foreach (var item in capabilitiesDictionary)
if (value == null)
{
object value = item.Value;

if (value == null)
{
continue;
}
continue;
}

if (typeof(string).IsAssignableFrom(value.GetType()))
if (typeof(string).IsAssignableFrom(value.GetType()))
{
if (AppiumServiceConstants.FilePathCapabilitiesForWindows.Contains(item.Key))
{
if (AppiumServiceConstants.FilePathCapabilitiesForWindows.Contains(item.Key))
{
value = $"\\\"{Convert.ToString(value).Replace("\\", "/")}\\\"";
}
else
{
value = $"\\\"{value}\\\"";
}
value = $"\\\"{Convert.ToString(value).Replace("\\", "/")}\\\"";
}
else
{
if (typeof(bool).IsAssignableFrom(value.GetType()))
{
value = Convert.ToString(value).ToLowerInvariant();
}
}

string key = $"\\\"{item.Key}\\\"";
if (string.IsNullOrEmpty(result))
{
result = $"{key}: {value}";
value = $"\\\"{value}\\\"";
}
else
}
else
{
if (typeof(bool).IsAssignableFrom(value.GetType()))
{
result = result + ", " + key + ": " + value;
value = Convert.ToString(value).ToLowerInvariant();
}
}

string key = $"\\\"{item.Key}\\\"";
result.Add($"{key}: {value}");
}

return "\"{" + result + "}\"";
return "\"{" + string.Join(", ", result) + "}\"";
}

private string ParseCapabilitiesIfUNIX()
Expand Down
Loading