The original code (~7.2s on my laptop).
import System.Random
import System.CPUTime
rainfall :: [Int] -> Int
rainfall xs = sum (zipWith (-) mins xs)
async Task Main() | |
{ | |
var c = new AsyncCache<int, int>(async x => { await Task.Delay(x); return x; }); | |
var s = Stopwatch.StartNew(); | |
var x1 = Enumerable.Range(1, 1000); | |
var results = | |
await Task.WhenAll(x1.Select(async x => | |
await Task.WhenAll( | |
// hit it in parallel |
void Main() | |
{ | |
var digits = Digits.Create("093884765"); | |
var digitsOfLength3 = Digits3.Create("007"); | |
Console.WriteLine($"digits: [{digits}] digitsOfLength3: [{digitsOfLength3}]"); | |
} | |
static class DigitsDef | |
{ |
using System; | |
using System.Collections.Concurrent; | |
using System.Threading; | |
using System.Threading.Tasks; | |
namespace ExampleLoop | |
{ | |
class Program | |
{ | |
const int maxQueuedItems = 10; |
#include <Windows.h> | |
#include <functional> | |
#include <memory> | |
#include <system_error> | |
void CALLBACK InvokeFunction(PTP_CALLBACK_INSTANCE, void* context, PTP_WORK) | |
{ | |
std::unique_ptr<std::function<void()>> owned{ static_cast<std::function<void()>*>(context) }; | |
(*owned)(); |
struct Six : Nat { public int Value => 6; } | |
void Main() | |
{ | |
var four = new Mod<Six>(4); | |
var two = new Mod<Six>(2); | |
Console.WriteLine(four + two == 0); | |
} |
{-# LANGUAGE RankNTypes, PolyKinds, TupleSections, TypeFamilies, TypeFamilyDependencies #-} | |
import Data.Kind (Type) | |
type LensFamily (outer :: t -> Type) (inner :: t -> Type) = | |
forall a b f. Functor f => (inner a -> f (inner b)) -> (outer a -> f (outer b)) | |
type family Snd b a = r | r -> b a where Snd b a = (a, b) | |
type family Fst a b = r | r -> a b where Fst a b = (a, b) | |
type family Id t = r | r -> t where Id x = x |
The original code (~7.2s on my laptop).
import System.Random
import System.CPUTime
rainfall :: [Int] -> Int
rainfall xs = sum (zipWith (-) mins xs)
// Implementations for: | |
// Select | |
// - { Enumerable, AsyncEnumerable } * { Action, Func, Func<_,Task>, Func<_,Task<T>> } | |
// = 8 | |
// - Enumerable/Action and Enumerable/Func (bad? and already defined) | |
// = 6 | |
// + 2 CancellationToken versions | |
// = 8 |
var surrogate = @"([\ud800-\udbff][\udc00-\udfff])";// .NET can't handle \U10000-\u10FFFF | |
var c = @"([\u0009\u000a\u000d\u0020-\ud7ff\ue000-\ufffd]|"+surrogate + ")"; | |
var s = @"([\u0020\u0009\u000d\u000a]+)"; | |
var nameStartChar = @"([:A-Z_a-z\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u02FF\u0370-\u037D\u037F-\u1FFF\u200C-\u200D\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD]|" + surrogate + ")"; | |
var nameChar = "(" + nameStartChar + @"|[-.0-9\u00B7\u0300-\u036F\u203F-\u2040])"; | |
var name = "(?'name'" + nameStartChar + nameChar + "*)"; | |
var names = "(?'names'" + name + @"(\u0020" + name +")*)"; | |
var nmtoken = "(?'nmtoken'" + nameChar + "+)"; | |
var nmtokens = "(?'nmtokens'" + nmtoken + @"(\u0020" + nmtoken +")*)"; | |
var pereference = "%" + name + ";"; |