Skip to content

Instantly share code, notes, and snippets.

View davepcallan's full-sized avatar

Dave Callan davepcallan

View GitHub Profile
@davepcallan
davepcallan / ReflectionBenchmarks.cs
Created July 19, 2022 12:48
.NET 6 v .NET 7 Reflection Benchmarks
using System.Linq;
using System.Reflection;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Columns;
using BenchmarkDotNet.Configs;
using BenchmarkDotNet.Jobs;
using BenchmarkDotNet.Reports;
namespace BenchmarkDotNet.Samples
{
using System.Collections.Generic;
using System.Linq;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Columns;
using BenchmarkDotNet.Configs;
using BenchmarkDotNet.Jobs;
using BenchmarkDotNet.Reports;
namespace BenchmarkDotNet.Samples
{
@davepcallan
davepcallan / SimpleStringConcatention.cs
Last active February 8, 2024 22:22
Simple String Concatenation .NET 6 v .NET 7
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Columns;
using BenchmarkDotNet.Jobs;
using System;
using System.Text;
namespace BenchmarkDotNet.Samples
{
[SimpleJob(RuntimeMoniker.Net60, baseline: true)]
[SimpleJob(RuntimeMoniker.Net70)]
@davepcallan
davepcallan / ChatGPT_controller_with_repository_example.cs
Created December 8, 2022 10:55
ChatGPT controller with injected repository example.
//Generate a .NET API ProductController which has hardcoded Products (in a repository
//which is injected into the ProductController constructor) and full crud actions
//using strongly typed DTOs which map to domain models using the explicit operator in C#.
using System.Collections.Generic;
using System.Linq;
using System.Web.Http;
namespace ProductAPI.Controllers
{
@davepcallan
davepcallan / Benchmarks.csproj
Last active February 8, 2024 19:05
LINQ 6 New features v .NET 7
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFrameworks>net6.0;net7.0;net8.0</TargetFrameworks>
<ImplicitUsings>disable</ImplicitUsings>
<LangVersion>latest</LangVersion>
</PropertyGroup>
<ItemGroup>
using System.Net.Http;
using System.Threading.Tasks;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Columns;
using BenchmarkDotNet.Configs;
using BenchmarkDotNet.Jobs;
using BenchmarkDotNet.Reports;
namespace BenchmarkDotNet.Samples
{
@davepcallan
davepcallan / Plus-v-StringBuilder-very-simple-concat.cs
Created January 14, 2023 14:12
Concat 50K one char strings with + and StringBuilder in .NET 7
using System.Text;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Columns;
using BenchmarkDotNet.Configs;
using BenchmarkDotNet.Jobs;
using BenchmarkDotNet.Reports;
namespace BenchmarkDotNet.Samples
{
[Config(typeof(Config))]
@davepcallan
davepcallan / Program.cs
Last active February 8, 2024 19:05
Benchmark to test difference between querying three normalized tables v one denormalized table for 10K records
using BenchmarkDotNet.Running;
internal class Program
{
private static void Main(string[] args)
{
//choose on command line from multiple benchmarks
BenchmarkSwitcher.FromAssembly(typeof(Program).Assembly).Run();
}
}
@davepcallan
davepcallan / Blog_schema_and_data.sql
Last active February 8, 2024 19:04
Entity Framework 7 GetType() examples
USE [EF7Inheritance]
GO
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Blogs]') AND type in (N'U'))
DROP TABLE [dbo].[Blogs]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[Blogs](
@davepcallan
davepcallan / Program.cs
Created January 22, 2023 09:39
.NET Framework 4.8 v .NET 7 Reflection Benchmarks
using BenchmarkDotNet.Running;
internal class Program
{
private static void Main(string[] args)
{
//choose on command line from multiple benchmarks
BenchmarkSwitcher.FromAssembly(typeof(Program).Assembly).Run();
}
}