Skip to content

Instantly share code, notes, and snippets.

View jahav's full-sized avatar

Jan Havlíček jahav

View GitHub Profile
@jahav
jahav / SoapCoreValidation.cs
Last active March 16, 2020 21:24
A demonstration of SoapCore filtering capabilities
using FluentValidation;
using FluentValidation.Results;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using SoapCore;
using SoapCore.Extensibility;
@jahav
jahav / ClosedXmlBenchmark.cs
Last active June 8, 2022 18:35
ClosedXML - Exception vs Return value benchmark
/*
My results
| Method | Mean | Error | StdDev |
|-------------- |-------------:|-----------:|-----------:|
| ReturnValue | 61.06 ns | 1.304 ns | 1.281 ns |
| ExceptionPath | 31,077.00 ns | 371.773 ns | 347.757 ns |
*/
public class FormulaExceptionVsReturnBenchmark : IDisposable
{
private readonly IXLWorkbook _workbook;
@jahav
jahav / ReturnVsExceptionBenchmark.cs
Created June 8, 2022 18:42
A simple benchmark to compare exception errors with error-indicating return values from performance points of view.
public class ReturnValueVsException
{
private readonly int _depth;
private readonly int _result;
public ReturnValueVsException(int depth = 1, int result = -1)
{
_depth = depth;
_result = result;
}
@jahav
jahav / ClosedXmlEvaluateExpr.cs
Created June 8, 2022 21:18
A benchmark to compare how expensive an exception is compare to a returned value.
/*
| Method | Mean | Error | StdDev |
|-------------- |-------------:|-----------:|-----------:|
| ReturnValue | 42.18 ns | 0.736 ns | 0.689 ns |
| ExceptionPath | 24,777.17 ns | 199.816 ns | 177.131 ns |
*/
public class FormulaExceptionVsReturnBenchmark
{
private string formExc = "=ABS(-1)/ABS(0)";
@jahav
jahav / benchmark-type-system.cs
Created August 5, 2022 19:11
A benchmark for simple comparison of previous parser and formula evaluation against XLParser and type system
using System;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Running;
using ClosedXML.Excel;
namespace ClosedXML.Sandbox
{
[RPlotExporter]
public class FormulaBenchmark
{
@jahav
jahav / ClosedXml-Sum.cs
Created August 10, 2022 08:09
An implementation of a SUM function for ClosedXml
ce.RegisterFunction("SUM", 1, int.MaxValue, Sum, FunctionFlags.Range, AllowRange.All);
private static AnyValue Sum(CalcContext ctx, Span<AnyValue?> args)
{
var sum = 0.0;
foreach (var nullableArg in args)
{
if (!nullableArg.HasValue)
continue;
@jahav
jahav / ClosedXml-CalcEngine-Benchamark.cs
Created September 4, 2022 17:02
A benchmark used during testing of revamped CalcEngine
using System.Collections.Generic;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Running;
using ClosedXML.Excel;
using NUnit.Framework;
namespace ClosedXML.Sandbox
{
[TestFixture]
[RPlotExporter]
@jahav
jahav / Test1594.cs
Created September 8, 2022 23:34
ClosedXML 1594 demo
public void Main()
{
var workbook = new XLWorkbook();
var worksheet = workbook.Worksheets.Add("Dati");
DataGenerationWithBigData(worksheet);
worksheet.Columns().AdjustToContents();
worksheet.PageSetup.PageOrientation = XLPageOrientation.Portrait;
@jahav
jahav / 1874-test.cs
Created December 16, 2022 22:07
Create a large file for test of issue 1874 for ClosedXML
DataTable dt = new DataTable();
DataColumn dc1 = new DataColumn("A", typeof(String));
DataColumn dc2 = new DataColumn("B", typeof(String));
DataColumn dc3 = new DataColumn("C", typeof(String));
DataColumn dc4 = new DataColumn("D", typeof(String));
DataColumn dc5 = new DataColumn("E", typeof(String));
DataColumn dc6 = new DataColumn("F", typeof(String));
DataColumn dc7 = new DataColumn("G", typeof(String));
DataColumn dc8 = new DataColumn("H", typeof(String));
using System;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;
using System.IO;
using System.Linq;
using ClosedXML.Excel;
namespace ClosedXML.Sandbox
{