-
-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0df6475
commit efddd3f
Showing
9 changed files
with
141 additions
and
37 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,71 @@ | ||
// | ||
// Copyright (c) .NET Foundation and Contributors | ||
// See LICENSE file in the project root for full license information. | ||
// | ||
|
||
using System; | ||
using System.Collections; | ||
using nanoFramework.Benchmark; | ||
using nanoFramework.Benchmark.Attributes; | ||
using nanoFramework.Json.Benchmark.Base; | ||
|
||
namespace nanoFramework.Json.Benchmark | ||
{ | ||
[IterationCount(100)] | ||
public class TypeBenchmarks: BaseIterationBenchmark | ||
{ | ||
protected override int IterationCount => 200; | ||
|
||
private readonly ArrayList _list = new(); | ||
private const string ArrayListFullName = "System.Collections.ArrayList"; | ||
private static readonly Type ArrayListType = typeof(ArrayList); | ||
|
||
[Benchmark] | ||
public void Benchmark_FullName_Comparison() | ||
{ | ||
RunInIteration(() => | ||
{ | ||
if (!ArrayListFullName.Equals(_list.GetType().FullName)) | ||
{ | ||
throw new ApplicationException(); | ||
} | ||
}); | ||
} | ||
|
||
[Benchmark] | ||
public void Benchmark_Type_Comparison() | ||
{ | ||
RunInIteration(() => | ||
{ | ||
if (_list.GetType() != typeof(ArrayList)) | ||
{ | ||
throw new ApplicationException(); | ||
} | ||
}); | ||
} | ||
|
||
[Benchmark] | ||
public void Benchmark_Type_Comparison_Static() | ||
{ | ||
RunInIteration(() => | ||
{ | ||
if (_list.GetType() != ArrayListType) | ||
{ | ||
throw new ApplicationException(); | ||
} | ||
}); | ||
} | ||
|
||
[Benchmark] | ||
public void Benchmark_TypeUtils_Comparison() | ||
{ | ||
RunInIteration(() => | ||
{ | ||
if (!TypeUtils.IsArrayList(_list.GetType())) | ||
{ | ||
throw new ApplicationException(); | ||
} | ||
}); | ||
} | ||
} | ||
} |
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
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,23 @@ | ||
#nullable enable | ||
using System; | ||
using System.Collections; | ||
|
||
namespace nanoFramework.Json | ||
{ | ||
internal static class TypeUtils | ||
{ | ||
// A very small optimization occurs by caching these types | ||
public static readonly Type ArrayListType = typeof(ArrayList); | ||
public static readonly Type HashTableType = typeof(Hashtable); | ||
public static readonly Type StringType = typeof(string); | ||
public static readonly Type ValueTypeType = typeof(ValueType); | ||
|
||
public static bool IsArrayList(Type? type) => ArrayListType == type; | ||
|
||
public static bool IsHashTable(Type? type) => HashTableType == type; | ||
|
||
public static bool IsString(Type? type) => StringType == type; | ||
|
||
public static bool IsValueType(Type? type) => ValueTypeType == type?.BaseType; | ||
} | ||
} |
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