All Projects → reegeek → Structlinq

reegeek / Structlinq

Licence: mit
Implementation in C# of LINQ concept with struct

Programming Languages

csharp
926 projects

Projects that are alternatives of or similar to Structlinq

cstruct-go
a fast c-style struct packer & unpacker for golang
Stars: ✭ 28 (-73.58%)
Mutual labels:  fast, struct
Geotic
Entity Component System library for javascript
Stars: ✭ 97 (-8.49%)
Mutual labels:  fast
Liblognorm
a fast samples-based log normalization library
Stars: ✭ 81 (-23.58%)
Mutual labels:  fast
Arangoclient.net
ArangoDB .NET Client with LINQ support
Stars: ✭ 94 (-11.32%)
Mutual labels:  linq
Linq To Astar
A* written in C#, used with LINQ.
Stars: ✭ 87 (-17.92%)
Mutual labels:  linq
Protoc Gen Gotag
Add custom struct tags to protobuf generated structs
Stars: ✭ 97 (-8.49%)
Mutual labels:  struct
Beebjit
A very fast BBC Micro emulator.
Stars: ✭ 81 (-23.58%)
Mutual labels:  fast
Mapster
A fast, fun and stimulating object to object Mapper
Stars: ✭ 1,375 (+1197.17%)
Mutual labels:  fast
Wg Install
Wireguard road warrior installer for Ubuntu, Debian, CentOS and Fedora
Stars: ✭ 99 (-6.6%)
Mutual labels:  fast
Linq To Wiki
.Net library to access MediaWiki API
Stars: ✭ 93 (-12.26%)
Mutual labels:  linq
Smart Array To Tree
Convert large amounts of data array to tree fastly
Stars: ✭ 91 (-14.15%)
Mutual labels:  fast
Magpie
🐦 Successor of my monkey Interpreter(support for class, linq, sql, net, http, fmt, json and A realtime syntax highlighting REPL).
Stars: ✭ 88 (-16.98%)
Mutual labels:  linq
Vex Hugo
Vex is a product landing page theme/template created by Themefisher based on the latest Bootstrap 4 framework. It is fully responsive and beautifully crafted with Product Showcase, Testimonials, and Email Subscription sections
Stars: ✭ 97 (-8.49%)
Mutual labels:  fast
Ofxfontstash
Easy (and fast) unicode string rendering addon for OpenFrameworks. FontStash is made by Andreas Krinke and Mikko Mononen
Stars: ✭ 84 (-20.75%)
Mutual labels:  fast
Cn sort
中文排序:按拼音/笔顺快速排序简体中文词组(百万数量级,可含中英/多音字)。如果对您有所帮助,欢迎点个star鼓励一下。
Stars: ✭ 102 (-3.77%)
Mutual labels:  fast
Nuxt Stories
Nuxt stories module -- Painless (and now insanely fast) storybooking for Nuxt
Stars: ✭ 81 (-23.58%)
Mutual labels:  fast
Cdnjs
🤖 CDN assets - The #1 free and open source CDN built to make life easier for developers.
Stars: ✭ 9,270 (+8645.28%)
Mutual labels:  fast
Libigl Python Bindings
IGL python bindings
Stars: ✭ 95 (-10.38%)
Mutual labels:  fast
Magnitude
A fast, efficient universal vector embedding utility package.
Stars: ✭ 1,394 (+1215.09%)
Mutual labels:  fast
Borm
【🔥今日热门】🏎️ 更好的ORM库 (Better ORM library that is simple, fast and self-mockable for Go)
Stars: ✭ 102 (-3.77%)
Mutual labels:  fast

StructLinq

GitHub release
Nuget Nuget
Build Status continuous
GitHub stars GitHub forks License

Implementation in C# of LINQ concept with struct to reduce drastically memory allocation and improve performance. Introduce IRefStructEnumerable to improve performance when element are fat struct.



Installation

This library is distributed via NuGet. To install StructLinq :

PM> Install-Package StructLinq

To install BCL wrapper use Struct.Linq.BCL :

PM> Install-Package StructLinq.BCL

Usage

StructLinq use massively generic concept and struct "specialization".

using StructLinq;
 
int[] array = new [] {1, 2, 3, 4, 5};

int result = array
                .ToStructEnumerable()
                .Where(x => (x & 1) == 0, x=>x)
                .Select(x => x *2, x => x)
                .Sum();

x=>x is used to avoid boxing (and allocation) and to help generic type parameters inference. You can also improve performance by using struct for Where predicate and select function.

Performances

All benchmark results are in here. For example following linq sequence:

   list
     .Where(x => (x & 1) == 0)
     .Select(x => x * 2)
     .Sum();

can be replace by:

  list
    .ToStructEnumerable()
    .Where(x => (x & 1) == 0)
    .Select(x => x * 2)
    .Sum();

or if you want zero allocation by:

 list
   .ToStructEnumerable()
   .Where(x => (x & 1) == 0, x=>x)
   .Select(x => x * 2, x=>x)
   .Sum(x=>x);

or if you want zero allocation and better performance by:

  var where = new WherePredicate();
  var select = new SelectFunction();
  list
    .ToStructEnumerable()
    .Where(ref @where, x => x)
    .Select(ref @select, x => x, x => x)
    .Sum(x => x);

Benchmark results are:

BenchmarkDotNet=v0.12.1, OS=Windows 10.0.19042
Intel Core i7-8750H CPU 2.20GHz (Coffee Lake), 1 CPU, 12 logical and 6 physical cores
.NET Core SDK=5.0.101
  [Host]     : .NET Core 5.0.1 (CoreCLR 5.0.120.57516, CoreFX 5.0.120.57516), X64 RyuJIT
  DefaultJob : .NET Core 5.0.1 (CoreCLR 5.0.120.57516, CoreFX 5.0.120.57516), X64 RyuJIT


Method Mean Error StdDev Ratio Gen 0 Gen 1 Gen 2 Allocated
LINQ 65.116 μs 0.6153 μs 0.5756 μs 1.00 - - - 152 B
StructLinqWithDelegate 26.146 μs 0.2402 μs 0.2247 μs 0.40 - - - 96 B
StructLinqWithDelegateZeroAlloc 27.854 μs 0.0938 μs 0.0783 μs 0.43 - - - -
StructLinqZeroAlloc 6.872 μs 0.0155 μs 0.0137 μs 0.11 - - - -

StructLinq is significatively faster than default LINQ implementation.

Features

Duck typing with foreach is available with zero allocation for IStructEnumerable.

BCL

Following class have a StructLinq extension method for IStructEnumerable:

Converters

Following converters are available for :

LINQ Extensions

Following extensions are available for :

Other Extensions

  • LongCount
  • UIntCount
  • Order
  • TryFirst

IRefStructEnumerable

    public interface IRefStructEnumerable<out T, out TEnumerator>
        where TEnumerator : struct, IRefStructEnumerator<T>
    {
        TEnumerator GetEnumerator();
    }

    public interface IRefStructEnumerator<T>
    {
        bool MoveNext();

        void Reset();

        ref T Current { get; }
    }

ref Current allows to avoid copy. I should be very useful when T is a fat struct.

Duck typing with foreach with ref is available with zero allocation for IRefStructEnumerable.

BCL

Following class have a StructLinq extension method for IRefStructEnumerable:

Converters

Following converters are available for :

LINQ Extensions

Following extensions are available for :

  • All
  • Any
  • Concat
  • Contains
  • Count
  • Distinct
  • ElementAt
  • ElementAtOrDefault
  • Except
  • First
  • FirstOrDefault
  • Intersect
  • Last
  • Select
  • Skip
  • Sum
  • Take
  • Union
  • Where

Other Extensions

  • LongCount
  • UIntCount
  • TryFirst
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].