Skip to content

Instantly share code, notes, and snippets.

View jahav's full-sized avatar

Jan Havlíček jahav

View GitHub Profile
@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 / 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 / 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 / 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 / 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 / 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;