Files
Umbraco-CMS/tests/Umbraco.Tests.Benchmarks/TryConvertToBenchmarks.cs

30 lines
1.1 KiB
C#
Raw Normal View History

using System;
2018-03-27 16:42:52 +02:00
using System.Collections.Generic;
using System.Linq;
2018-03-27 16:42:52 +02:00
using BenchmarkDotNet.Attributes;
using Umbraco.Extensions;
2018-03-27 16:42:52 +02:00
namespace Umbraco.Tests.Benchmarks;
[MemoryDiagnoser]
public class TryConvertToBenchmarks
2018-03-27 16:42:52 +02:00
{
private static readonly List<string> List = new() { "hello", "world", "awesome" };
private static readonly string Date = "Saturday 10, November 2012";
2018-03-27 16:42:52 +02:00
[Benchmark(Description = "List<string> to IEnumerable<string>")]
public IList<string> TryConvertToEnumerable() => List.TryConvertTo<IEnumerable<string>>().Result.ToList();
2018-03-27 16:42:52 +02:00
[Benchmark(Description = "Int to Double")]
public double TryConvertToDouble() => 1.TryConvertTo<double>().Result;
2018-03-27 16:42:52 +02:00
[Benchmark(Description = "Float to Decimal")]
public decimal TryConvertToDecimal() => 1F.TryConvertTo<decimal>().Result;
2018-03-27 16:42:52 +02:00
[Benchmark(Description = "String to Boolean")]
public bool TryConvertToBoolean() => "1".TryConvertTo<bool>().Result;
2018-03-27 16:42:52 +02:00
[Benchmark(Description = "String to DateTime")]
public DateTime TryConvertToDateTime() => Date.TryConvertTo<DateTime>().Result;
}