Public
Star 历史趋势
数据来源: GitHub API · 生成自 Stargazers.cn
README.md

Sep - the World's Fastest .NET CSV Parser

.NET C# Build Status Super-Linter codecov CodeQL Nuget Release downloads Size License Blog GitHub Repo stars

Icon

Modern, minimal, fast, zero allocation, reading and writing of separated values (csv, tsv etc.). Cross-platform, trimmable and AOT/NativeAOT compatible. Featuring an opinionated API design and pragmatic implementation targeted at machine learning use cases.

⭐ Please star this project if you like it. ⭐

🌃 Modern - utilizes features such as Span<T>, Generic Math (ISpanParsable<T>/ ISpanFormattable), ref struct, ArrayPool<T> and similar from .NET 7+ and C# 11+ for a modern and highly efficient implementation.

🔎 Minimal - a succinct yet expressive API with few options and no hidden changes to input or output. What you read/write is what you get. E.g. by default there is no "automatic" escaping/unescaping of quotes or trimming of spaces. To enable this see SepReaderOptions and Unescaping and Trimming. See SepWriterOptions for Escaping.

🚀 Fast - blazing fast with both architecture specific and cross-platform SIMD vectorized parsing incl. 64/128/256/512-bit paths e.g. AVX2, AVX-512 (.NET 8.0+), NEON. Uses csFastFloat for fast parsing of floating points. See detailed benchmarks for cross-platform results.

🌪️ Multi-threaded - unparalleled speed with highly efficient parallel CSV parsing that is up to 35x faster than CsvHelper, see ParallelEnumerate and benchmarks.

🌀 Async support - efficient ValueTask based async/await support. Requires C# 13.0+ and for .NET 9.0+ includes SepReader implementing IAsyncEnumerable<>. See Async Support for details.

🗑️ Zero allocation - intelligent and efficient memory management allowing for zero allocations after warmup incl. supporting use cases of reading or writing arrays of values (e.g. features) easily without repeated allocations.

✅ Thorough tests - great code coverage and focus on edge case testing incl. randomized fuzz testing.

🌐 Cross-platform - works on any platform, any architecture supported by NET. 100% managed and written in beautiful modern C#.

✂️ Trimmable and AOT/NativeAOT compatible - no problematic reflection or dynamic code generation. Hence, fully trimmable and Ahead-of-Time compatible. With a simple console tester program executable possible in just a few MBs. 💾

🗣️ Opinionated and pragmatic - conforms to the essentials of RFC-4180, but takes an opinionated and pragmatic approach towards this especially with regards to quoting and line ends. See section RFC-4180.

Example | Naming and Terminology | API | Limitations and Constraints | Comparison Benchmarks | Example Catalogue | RFC-4180 | FAQ | Public API Reference

Example

var text = """ A;B;C;D;E;F Sep;🚀;1;1.2;0.1;0.5 CSV;;2;2.2;0.2;1.5 """; using var reader = Sep.Reader().FromText(text); // Infers separator 'Sep' from header using var writer = reader.Spec.Writer().ToText(); // Writer defined from reader 'Spec' // Use .FromFile(...)/ToFile(...) for files var idx = reader.Header.IndexOf("B"); var nms = new[] { "E", "F" }; foreach (var readRow in reader) // Read one row at a time { var a = readRow["A"].Span; // Column as ReadOnlySpan<char> var b = readRow[idx].ToString(); // Column to string (might be pooled) var c = readRow["C"].Parse<int>(); // Parse any T : ISpanParsable<T> var d = readRow["D"].Parse<float>(); // Parse float/double fast via csFastFloat var s = readRow[nms].Parse<double>(); // Parse multiple columns as Span<T> // - Sep handles array allocation and reuse foreach (ref var v in s) { v *= 10; } using var writeRow = writer.NewRow(); // Start new row. Row written on Dispose. writeRow["A"].Set(a); // Set by ReadOnlySpan<char> writeRow["B"].Set(b); // Set by string writeRow["C"].Set($"{c * 2}"); // Set via InterpolatedStringHandler, no allocs writeRow["D"].Format(d / 2); // Format any T : ISpanFormattable writeRow[nms].Format(s); // Format multiple columns directly // Columns are added on first access as ordered, header written when first row written } var expected = """ A;B;C;D;E;F Sep;🚀;2;0.6;1;5 CSV;;4;1.1;2;15 """; // Empty line at end is for line ending, // which is always written. Assert.AreEqual(expected, writer.ToString()); // Above example code is for demonstration purposes only. // Short names and repeated constants are only for demonstration.

For more examples, incl. how to write and read objects (e.g. records) with escape/unescape support, see Example Catalogue.

Naming and Terminology

Sep uses naming and terminology that is not based on RFC-4180, but is more tailored to usage in machine learning or similar. Additionally, Sep takes a pragmatic approach towards names by using short names and abbreviations where it makes sense and there should be no ambiguity given the context. That is, using Sep for Separator and Col for Column to keep code succinct.

TermDescription
SepShort for separator, also called delimiter. E.g. comma (,) is the separator for the separated values in a csv-file.
HeaderOptional first row defining names of columns.
RowA row is a collection of col(umn)s, which may span multiple lines. Also called record.
ColShort for column, also called field.
LineHorizontal set of characters until a line ending; \r\n, \r, \n.
Index0-based that is RowIndex will be 0 for first row (or the header if present).
Number1-based that is LineNumber will be 1 for the first line (as in notepad). Given a row may span multiple lines a row can have a From line number and a ToExcl line number matching the C# range indexing syntax [LineNumberFrom..LineNumberToExcl].

Application Programming Interface (API)

Besides being the succinct name of the library, Sep is both the main entry point to using the library and the container for a validated separator. That is, Sep is basically defined as:

public readonly record struct Sep(char Separator);

The separator char is validated upon construction and is guaranteed to be within a limited range and not being a char like " (quote) or similar. This can be seen in src/Sep/Sep.cs. The separator is constrained also for internal optimizations, so you cannot use any char as a separator.

⚠ Note that all types are within the namespace nietras.SeparatedValues and not Sep since it is problematic to have a type and a namespace with the same name.

To get started you can use Sep as the static entry point to building either a reader or writer. That is, for SepReader:

using var reader = Sep.Reader().FromFile("titanic.csv");

where .Reader() is a convenience method corresponding to:

using var reader = Sep.Auto.Reader().FromFile("titanic.csv");

where Sep? Auto => null; is a static property that returns null for a nullable Sep to signify that the separator should be inferred from the first row, which might be a header. If the first row does not contain any of the by default supported separators or there are no rows, the default separator will be used.

⚠ Note Sep uses ; as the default separator, since this is what was used in an internal proprietary library which Sep was built to replace. This is also to avoid issues with comma , being used as a decimal separator in some locales. Without having to resort to quoting.

If you want to specify the separator you can write:

using var reader = Sep.New(',').Reader().FromFile("titanic.csv");

or

var sep = new Sep(','); using var reader = sep.Reader().FromFile("titanic.csv");

Similarly, for SepWriter:

using var writer = Sep.Writer().ToFile("titanic.csv");

or

using var writer = Sep.New(',').Writer().ToFile("titanic.csv");

where you have to specify a valid separator, since it cannot be inferred. To fascillitate easy flow of the separator and CultureInfo both SepReader and SepWriter expose a Spec property of type SepSpec that simply defines those two. This means you can write:

using var reader = Sep.Reader().FromFile("titanic.csv"); using var writer = reader.Spec.Writer().ToFile("titanic-survivors.csv");

where the writer then will use the separator inferred by the reader, for example.

API Pattern

In general, both reading and writing follow a similar pattern:

Sep/Spec => SepReaderOptions => SepReader => Row => Col(s) => Span/ToString/Parse Sep/Spec => SepWriterOptions => SepWriter => Row => Col(s) => Set/Format

where each continuation flows fluently from the preceding type. For example, Reader() is an extension method to Sep or SepSpec that returns a SepReaderOptions. Similarly, Writer() is an extension method to Sep or SepSpec that returns a SepWriterOptions.

SepReaderOptions and SepWriterOptions are optionally configurable. That and the APIs for reader and writer is covered in the following sections.

For a complete example, see the example above or the ReadMeTest.cs.

⚠ Note that it is important to understand that Sep Row/Col/Cols are ref structs (please follow the ref struct link and understand how this limits the usage of those). This is due to these types being simple facades or indirections to the underlying reader or writer. That means you cannot use LINQ or create an array of all rows like reader.ToArray(). While for .NET9+ the reader is now IEnumerable<> since ref structs can now be used in interfaces that have where T: allows ref struct this still does not mean it is LINQ compatible. Hence, if you need store per row state or similar you need to parse or copy to different types instead. The same applies to Col/Cols which point to internal state that is also reused. This is to avoid repeated allocations for each row and get the best possible performance, while still defining a well structured and straightforward API that guides users to relevant functionality. See Why SepReader Was Not IEnumerable Until .NET 9 and Is Not LINQ Compatible for more.

⚠ For a full overview of public types and methods see Public API Reference.

SepReader API

SepReader API has the following structure (in pseudo-C# code):

using var reader = Sep.Reader(o => o).FromFile/FromText/From...; var header = reader.Header; var _ = header.IndexOf/IndicesOf/NamesStartingWith...; foreach (var row in reader) { var _ = row[colName/colNames].Span/ToString/Parse<T>...; var _ = row[colIndex/colIndices].Span/ToString/Parse<T>...; }

That is, to use SepReader follow the points below:

  1. Optionally define Sep or use default automatically inferred separator.
  2. Specify reader with optional configuration of SepReaderOptions. For example, if a csv-file does not have a header this can be configured via:
    Sep.Reader(o => o with { HasHeader = false })
    For all options see SepReaderOptions.
  3. Specify source e.g. file, text (string), TextWriter, etc. via From extension methods.
  4. Optionally access the header. For example, to get all columns starting with GT_ use:
    var colNames = header.NamesStarting("GT_"); var colIndices = header.IndicesOf(colNames);
  5. Enumerate rows. One row at a time.
  6. Access a column by name or index. Or access multiple columns with names and indices. Sep internally handles pooled allocation and reuse of arrays for multiple columns.
  7. Use Span to access the column directly as a ReadOnlySpan<char>. Or use ToString to convert to a string. Or use Parse<T> where T : ISpanParsable<T> to parse the column chars to a specific type.

SepReaderOptions

The following options are available:

/// <summary> /// Specifies the separator used, if `null` then automatic detection /// is used based on first row in source. /// </summary> public Sep? Sep { get; init; } = null; /// <summary> /// Specifies initial internal `char` buffer length. /// </summary> /// <remarks> /// The length will likely be rounded up to the nearest power of 2. A /// smaller buffer may end up being used if the underlying source for <see /// cref="System.IO.TextReader"/> is known to be smaller. Prefer to keep the /// default length as that has been tuned for performance and cache sizes. /// Avoid making this unnecessarily large as that will likely not improve /// performance and may waste memory. /// </remarks> public int InitialBufferLength { get; init; } = SepDefaults.InitialBufferLength; /// <summary> /// Specifies the culture used for parsing. /// May be `null` for default culture. /// </summary> public CultureInfo? CultureInfo { get; init; } = SepDefaults.CultureInfo; /// <summary> /// Indicates whether the first row is a header row. /// </summary> public bool HasHeader { get; init; } = true; /// <summary> /// Specifies <see cref="IEqualityComparer{T}" /> to use /// for comparing header column names and looking up index. /// </summary> public IEqualityComparer<string> ColNameComparer { get; init; } = SepDefaults.ColNameComparer; /// <summary> /// Specifies the method factory used to convert a column span /// of `char`s to a `string`. /// </summary> public SepCreateToString CreateToString { get; init; } = SepToString.Direct; /// <summary> /// Disables using [csFastFloat](https://github.com/CarlVerret/csFastFloat) /// for parsing `float` and `double`. /// </summary> public bool DisableFastFloat { get; init; } = false; /// <summary> /// Disables checking if column count is the same for all rows. /// </summary> public bool DisableColCountCheck { get; init; } = false; /// <summary> /// Disables detecting and parsing quotes. /// </summary> public bool DisableQuotesParsing { get; init; } = false; /// <summary> /// Unescape quotes on column access. /// </summary> /// <remarks> /// When true, if a column starts with a quote then the two outermost quotes /// are removed and every second inner quote is removed. Note that /// unquote/unescape happens in-place, which means the <see /// cref="SepReader.Row.Span" /> will be modified and contain "garbage" /// state after unescaped cols before next col. This is for efficiency to /// avoid allocating secondary memory for unescaped columns. Header /// columns/names will also be unescaped. /// Requires <see cref="DisableQuotesParsing"/> to be false. /// </remarks> public bool Unescape { get; init; } = false; /// <summary> /// Option for trimming spaces (` ` - ASCII 32) on column access. /// </summary> /// <remarks> /// By default no trimming is done. See <see cref="SepTrim"/> for options. /// Note that trimming may happen in-place e.g. if also unescaping, which /// means the <see cref="SepReader.Row.Span" /> will be modified and contain /// "garbage" state for trimmed/unescaped cols. This is for efficiency to /// avoid allocating secondary memory for trimmed/unescaped columns. Header /// columns/names will also be trimmed. Note that only the space ` ` (ASCII /// 32) character is trimmed, not any whitespace character. /// </remarks> public SepTrim Trim { get; init; } = SepTrim.None; /// <summary> /// Forwarded to <see /// cref="System.Threading.Tasks.ValueTask.ConfigureAwait(bool)"/> or /// similar when async methods are called. /// </summary> public bool AsyncContinueOnCapturedContext { get; init; } = false;

Unescaping

While great care has been taken to ensure Sep unescaping of quotes is both correct and fast, there is always the question of how does one respond to invalid input.

The below table tries to summarize the behavior of Sep vs CsvHelper and Sylvan. Note that all do the same for valid input. There are differences for how invalid input is handled. For Sep the design choice has been based on not wanting to throw exceptions and to use a principle that is both reasonably fast and simple.

InputValidCsvHelperCsvHelper¹SylvanSep²
aTrueaaaa
""True
""""True""""
""""""True""""""""
"a"Trueaaaa
"a""a"Truea"aa"aa"aa"a
"a""a""a"Truea"a"aa"a"aa"a"aa"a"a
a""aFalseEXCEPTIONa""aa""aa""a
a"a"aFalseEXCEPTIONa"a"aa"a"aa"a"a
·""·FalseEXCEPTION·""··""··""·
·"a"·FalseEXCEPTION·"a"··"a"··"a"·
·""FalseEXCEPTION·""·""·""
·"a"FalseEXCEPTION·"a"·"a"·"a"
a"""aFalseEXCEPTIONa"""aa"""aa"""a
"a"a"a"FalseEXCEPTIONaa"a"a"a"aaa"a
""·FalseEXCEPTION·"·
"a"·FalseEXCEPTIONa"
"a"""aFalseEXCEPTIONaaEXCEPTIONa"a
"a"""a"FalseEXCEPTIONaa"a"a<NULL>a"a"
""a"FalseEXCEPTIONa""aa"
"a"a"FalseEXCEPTIONaa"a"aaa"
""a"a""FalseEXCEPTIONa"a"""a"a"a"a"
"""FalseEXCEPTION"
"""""False""EXCEPTION""

· (middle dot) is whitespace to make this visible

¹ CsvHelper with BadDataFound = null

² Sep with Unescape = true in SepReaderOptions

Trimming

Sep supports trimming by the SepTrim flags enum, which has two options as documented there. Below the result of both trimming and unescaping is shown in comparison to CsvHelper. Note unescaping is enabled for all results shown. It is possible to trim without unescaping too, of course.

As can be seen Sep supports a simple principle of trimming before and after unescaping with trimming before unescaping being important for unescaping if there is a starting quote after spaces.

InputCsvHelper TrimCsvHelper InsideQuotesCsvHelper All¹Sep OuterSep AfterUnescapeSep All²
aaaaaaa
·aa·aaaaa
aaaaa
·a·a·a·aaaa
·a·a·a·a·a·a·a·aa·aa·aa·a
"a"aaaaaa
"·a"·aaa·aaa
"a·"aaaa
"·a·"·a·aa·a·aa
"·a·a·"·a·a·a·aa·a·a·a·a·aa·a
·"a"·a·"a"·aa"a"a
·"·a"··a·"·a"·a·a"·a"a
·"a·"··"a·"·a"a·"a
·"·a·"··a··"·a·"·a·a·"·a·"a
·"·a·a·"··a·a··"·a·a·"·a·a·a·a·"·a·a·"a·a

· (middle dot) is whitespace to make this visible

¹ CsvHelper with TrimOptions.Trim | TrimOptions.InsideQuotes

² Sep with SepTrim.All = SepTrim.Outer | SepTrim.AfterUnescape in SepReaderOptions

SepReader Debuggability

Debuggability is an important part of any library and while this is still a work in progress for Sep, SepReader does have a unique feature when looking at it and it's row or cols in a debug context. Given the below example code:

var text = """ Key;Value A;"1 2 3" B;"Apple Banana Orange Pear" """; using var reader = Sep.Reader().FromText(text); foreach (var row in reader) { // Hover over reader, row or col when breaking here var col = row[1]; if (Debugger.IsAttached && row.RowIndex == 2) { Debugger.Break(); } Debug.WriteLine(col.ToString()); }

and you are hovering over reader when the break is triggered then this will show something like:

String Length=55

That is, it will show information of the source for the reader, in this case a string of length 55.

SepReader.Row Debuggability

If you are hovering over row then this will show something like:

2:[5..9] = "B;\"Apple\r\nBanana\r\nOrange\r\nPear\""

This has the format shown below.

<ROWINDEX>:[<LINENUMBERRANGE>] = "<ROW>"

Note how this shows line number range [FromIncl..ToExcl], as in C# range expression, so that one can easily find the row in question in notepad or similar. This means Sep has to track line endings inside quotes and is an example of a feature that makes Sep a bit slower but which is a price considered worth paying.

GitHub doesn't show line numbers in code blocks so consider copying the example text to notepad or similar to see the effect.

Additionally, if you expand the row in the debugger (e.g. via the small triangle) you will see each column of the row similar to below.

00:'Key' = "B" 01:'Value' = "\"Apple\r\nBanana\r\nOrange\r\nPear\""
SepReader.Col Debuggability

If you hover over col you should see:

"\"Apple\r\nBanana\r\nOrange\r\nPear\""

Why SepReader Was Not IEnumerable Until .NET 9 and Is Not LINQ Compatible

As mentioned earlier Sep only allows enumeration and access to one row at a time and SepReader.Row is just a simple facade or indirection to the underlying reader. This is why it is defined as a ref struct. In fact, the following code:

using var reader = Sep.Reader().FromText(text); foreach (var row in reader) { }

can also be rewritten as:

using var reader = Sep.Reader().FromText(text); while (reader.MoveNext()) { var row = reader.Current; }

where row is just a facade for exposing row specific functionality. That is, row is still basically the reader underneath. Hence, let's look at using LINQ with SepReader implementing IEnumerable<SepReader.Row> and the Row not being a ref struct. Then, you would be able to write something like below:

using var reader = Sep.Reader().FromText(text); SepReader.Row[] rows = reader.ToArray();

Given Row is just a facade for the reader, this would be equivalent to writing:

using var reader = Sep.Reader().FromText(text); SepReader[] rows = reader.ToArray();

which hopefully makes it clear why this is not a good thing. The array would effectively be the reader repeated several times. If this would have to be supported one would have to allocate memory for each row always, which would basically be no different than a ReadLine approach as benchmarked in Comparison Benchmarks.

This is perhaps also the reason why no other efficient .NET CSV parser (known to author) implements an API pattern like Sep, but instead let the reader define all functionality directly and hence only let's you access the current row and cols on that. This API, however, is in this authors opinion not ideal and can be a bit confusing, which is why Sep is designed like it is. The downside is the above caveat.

The main culprit above is that for example ToArray() would store a ref struct in a heap allocated array, the actual enumeration is not a problem and hence implementing IEnumerable<SepReader.Row> is not the problem as such. The problem was that prior to .NET 9 it was not possible to implement this interface with T being a ref struct, but with C# 13 allows ref struct and .NET 9 having annotated such interfaces it is now possible and you can assign SepReader to IEnumerable, but most if not all of LINQ will still not work as shown below.

var text = """ Key;Value A;1.1 B;2.2 """; using var reader = Sep.Reader().FromText(text); IEnumerable<SepReader.Row> enumerable = reader; // Currently, most LINQ methods do not work for ref types. See below. // // The type 'SepReader.Row' may not be a ref struct or a type parameter // allowing ref structs in order to use it as parameter 'TSource' in the // generic type or method 'Enumerable.Select<TSource, // TResult>(IEnumerable<TSource>, Func<TSource, TResult>)' // // enumerable.Select(row => row["Key"].ToString()).ToArray();

Calling Select should in principle be possible if this was annotated with allows ref struct, but it isn't currently.

If you want to use LINQ or similar you have to first parse or transform the rows into some other type and enumerate it. This is easy to do and instead of counting lines you should focus on how such enumeration can be easily expressed using C# iterators (aka yield return). With local functions this can be done inside a method like:

var text = """ Key;Value A;1.1 B;2.2 """; var expected = new (string Key, double Value)[] { ("A", 1.1), ("B", 2.2), }; using var reader = Sep.Reader().FromText(text); var actual = Enumerate(reader).ToArray(); CollectionAssert.AreEqual(expected, actual); static IEnumerable<(string Key, double Value)> Enumerate(SepReader reader) { foreach (var row in reader) { yield return (row["Key"].ToString(), row["Value"].Parse<double>()); } }

Now if instead refactoring this to something LINQ-compatible by defining a common Enumerate or similar method it could be:

var text = """ Key;Value A;1.1 B;2.2 """; var expected = new (string Key, double Value)[] { ("A", 1.1), ("B", 2.2), }; using var reader = Sep.Reader().FromText(text); var actual = Enumerate(reader, row => (row["Key"].ToString(), row["Value"].Parse<double>())) .ToArray(); CollectionAssert.AreEqual(expected, actual); static IEnumerable<T> Enumerate<T>(SepReader reader, SepReader.RowFunc<T> select) { foreach (var row in reader) { yield return select(row); } }

In fact, Sep provides such a convenience extension method. And, discounting the Enumerate method, this does have less boilerplate, but not really more effective lines of code. The issue here is that this tends to favor factoring code in a way that can become very inefficient quickly. Consider if one wanted to only enumerate rows matching a predicate on Key which meant only 1% of rows were to be enumerated e.g.:

var text = """ Key;Value A;1.1 B;2.2 """; var expected = new (string Key, double Value)[] { ("B", 2.2), }; using var reader = Sep.Reader().FromText(text); var actual = reader.Enumerate( row => (row["Key"].ToString(), row["Value"].Parse<double>())) .Where(kv => kv.Item1.StartsWith('B')) .ToArray(); CollectionAssert.AreEqual(expected, actual);

This means you are still parsing the double (which is magnitudes slower than getting just the key) for all rows. Imagine if this was an array of floating points or similar. Not only would you then be parsing a lot of values you would also be allocated 99x arrays that aren't used after filtering with Where.

Instead, you should focus on how to express the enumeration in a way that is both efficient and easy to read. For example, the above could be rewritten as:

var text = """ Key;Value A;1.1 B;2.2 """; var expected = new (string Key, double Value)[] { ("B", 2.2), }; using var reader = Sep.Reader().FromText(text); var actual = Enumerate(reader).ToArray(); CollectionAssert.AreEqual(expected, actual); static IEnumerable<(string Key, double Value)> Enumerate(SepReader reader) { foreach (var row in reader) { var keyCol = row["Key"]; if (keyCol.Span.StartsWith("B")) { yield return (keyCol.ToString(), row["Value"].Parse<double>()); } } }

To accommodate this Sep provides an overload for Enumerate that is similar to:

static IEnumerable<T> Enumerate<T>(this SepReader reader, SepReader.RowTryFunc<T> trySelect) { foreach (var row in reader) { if (trySelect(row, out var value)) { yield return value; } } }

With this the above custom Enumerate can be replaced with:

var text = """ Key;Value A;1.1 B;2.2 """; var expected = new (string Key, double Value)[] { ("B", 2.2), }; using var reader = Sep.Reader().FromText(text); var actual = reader.Enumerate((SepReader.Row row, out (string Key, double Value) kv) => { var keyCol = row["Key"]; if (keyCol.Span.StartsWith("B")) { kv = (keyCol.ToString(), row["Value"].Parse<double>()); return true; } kv = default; return false; }).ToArray(); CollectionAssert.AreEqual(expected, actual);

Note how this is pretty much the same length as the previous custom Enumerate. Also worse due to how C# requires specifying types for out parameters which then requires all parameter types for the lambda to be specified. Hence, in this case the custom Enumerate does not take significantly longer to write and is a lot more efficient than using LINQ .Where (also avoids allocating a string for key for each row) and is easier to debug and perhaps even read. All examples above can be seen in ReadMeTest.cs.

There is a strong case for having an enumerate API though and that is for parallelized enumeration, which will be discussed next.

ParallelEnumerate and Enumerate

As discussed in the previous section Sep provides Enumerate convenience extension methods, that should be used carefully. Alongside these there are ParallelEnumerate extension methods that provide very efficient multi-threaded enumeration. See benchmarks for numbers and Public API Reference.

ParallelEnumerate is build on top of LINQ AsParallel().AsOrdered() and will return exactly the same as Enumerate but with enumeration parallelized. This will use more memory during execution and as many threads as possible via the .NET thread pool. When using ParallelEnumerate one should, therefore (as always), be certain the provided delegate does not refer to or change any mutable state.

ParallelEnumerate comes with a lot of overhead compared to single-threaded foreach or Enumerate and should be used carefully based on measuring any potential benefit. Sep goes a long way to make this very efficient by using pooled arrays and parsing multiple rows in batches, but if the source only has a few rows then any benefit is unlikely.

Due to ParallelEnumerate being based on batches of rows it is also important not to "abuse" it in-place of LINQ AsParallel. The idea is to use it for parsing rows, not for doing expensive per row operations like loading an image or similar. In that case, you are better off using AsParallel() after ParallelEnumerate or Enumerate similarly to:

using var reader = Sep.Reader().FromFile("very-long.csv"); var results = reader.ParallelEnumerate(ParseRow) .AsParallel().AsOrdered() .Select(LoadData) // Expensive load .ToList();

As a rule of thumb if the time per row exceeds 1 millisecond consider moving the expensive work to after ParallelEnumerate/Enumerate,

SepWriter API

SepWriter API has the following structure (in pseudo-C# code):

using var writer = Sep.Writer(o => o).ToFile/ToText/To...; foreach (var data in EnumerateData()) { using var row = writer.NewRow(); var _ = row[colName/colNames].Set/Format<T>...; var _ = row[colIndex/colIndices].Set/Format<T>...; }

That is, to use SepWriter follow the points below:

  1. Optionally define Sep or use default automatically inferred separator.
  2. Specify writer with optional configuration of SepWriterOptions. For all options see SepWriterOptions.
  3. Specify destination e.g. file, text (string via StringWriter), TextWriter, etc. via To extension methods.
  4. MISSING: SepWriter currently does not allow you to define the header up front. Instead, header is defined by the order in which column names are accessed/created when defining the row.
  5. Define new rows with NewRow. ⚠ Be sure to dispose any new rows before starting the next! For convenience Sep provides an overload for NewRow that takes a SepReader.Row and copies the columns from that row to the new row:
    using var reader = Sep.Reader().FromText(text); using var writer = reader.Spec.Writer().ToText(); foreach (var readRow in reader) { using var writeRow = writer.NewRow(readRow); }
  6. Create a column by selecting by name or index. Or multiple columns via indices and names. Sep internally handles pooled allocation and reuse of arrays for multiple columns.
  7. Use Set to set the column value either as a ReadOnlySpan<char>, string or via an interpolated string. Or use Format<T> where T : IFormattable to format T to the column value.
  8. Row is written when Dispose is called on the row.

    Note this is to allow a row to be defined flexibly with both column removal, moves and renames in the future. This is not yet supported.

SepWriterOptions

The following options are available:

/// <summary> /// Specifies the separator used. /// </summary> public Sep Sep { get; init; } /// <summary> /// Specifies the culture used for parsing. /// May be `null` for default culture. /// </summary> public CultureInfo? CultureInfo { get; init; } /// <summary> /// Specifies whether to write a header row /// before data rows. Requires all columns /// to have a name. Otherwise, columns can be /// added by indexing alone. /// </summary> public bool WriteHeader { get; init; } = true; /// <summary> /// Disables checking if column count is the /// same for all rows. /// </summary> /// <remarks> /// When true, the <see cref="ColNotSetOption"/> /// will define how columns that are not set /// are handled. For example, whether to skip /// or write an empty column if a column has /// not been set for a given row. /// <para> /// If any columns are skipped, then columns of /// a row may, therefore, be out of sync with /// column names if <see cref="WriteHeader"/> /// is true. /// </para> /// As such, any number of columns can be /// written as long as done sequentially. /// </remarks> public bool DisableColCountCheck { get; init; } = false; /// <summary> /// Specifies how to handle columns that are /// not set. /// </summary> public SepColNotSetOption ColNotSetOption { get; init; } = SepColNotSetOption.Throw; /// <summary> /// Specifies whether to escape column names /// and values when writing. /// </summary> /// <remarks> /// When true, if a column contains a separator /// (e.g. `;`), carriage return (`\r`), line /// feed (`\n` or quote (`"`) then the column /// is prefixed and suffixed with quotes `"` /// and any quote in the column is escaped by /// adding an extra quote so it becomes `""`. /// Note that escape applies to column names /// too, but only the written name. /// </remarks> public bool Escape { get; init; } = false; /// <summary> /// Forwarded to <see /// cref="System.Threading.Tasks.ValueTask.ConfigureAwait(bool)"/> or /// similar when async methods are called. /// </summary> public bool AsyncContinueOnCapturedContext { get; init; } = false;

Escaping

Escaping is not enabled by default in Sep, but when it is it gives the same results as other popular CSV librares as shown below. Although, CsvHelper appears to be escaping spaces as well, which is not necessary.

InputCsvHelperSylvanSep¹
``
·"·"··
aaaa
;";"";"";"
,,,,
"""""""""""""
\r"\r""\r""\r"
\n"\n""\n""\n"
a"aa"aaa"a""aa""aaa""a""aa""aaa""a""aa""aaa"
a;aa;aaa"a;aa;aaa""a;aa;aaa""a;aa;aaa"

Separator/delimiter is set to semi-colon ; (default for Sep)

· (middle dot) is whitespace to make this visible

\r, \n are carriage return and line feed special characters to make these visible

¹ Sep with Escape = true in SepWriterOptions

Async Support

Sep supports efficient ValueTask based asynchronous reading and writing.

However, given both SepReader.Row and SepWriter.Row are ref structs, as they point to internal state and should only be used one at a time, async/await usage is only supported on C# 13.0+ as this has support for "ref and unsafe in iterators and async methods" as covered in What's new in C# 13. Please consult details in that for limitations and constraints due to this.

Similarly, SepReader only implements IAsyncEnumerable<SepReader.Row> (and IEnumerable<SepReader.Row>) for .NET 9.0+/C# 13.0+ since then the interfaces have been annotated with allows ref struct for T.

Async support is provided on the existing SepReader and SepWriter types similar to how TextReader and TextWriter support both sync and async usage. This means you as a developer are responsible for calling async methods and using await when necessary. See below for a simple example and consult tests on GitHub for more examples.

var text = """ A;B;C;D;E;F Sep;🚀;1;1.2;0.1;0.5 CSV;;2;2.2;0.2;1.5 """; // Empty line at end is for line ending using var reader = await Sep.Reader().FromTextAsync(text); await using var writer = reader.Spec.Writer().ToText(); await foreach (var readRow in reader) { await using var writeRow = writer.NewRow(readRow); } Assert.AreEqual(text, writer.ToString());

Note how for SepReader the FromTextAsync is suffixed with Async to indicate async creation, this is due to the reader having to read the first row of the source at creation to determine both separator and, if file has a header, column names of the header. The From*Async call then has to be awaited. After that rows can be enumerated asynchronously simply by putting await before foreach. If one forgets to do that the rows will be enumerated synchronously.

For SepWriter the usage is kind of reversed. To* methods have no Async variants, since creation is synchronous. That is, StreamWriter is created by a simple constructor call. Nothing is written until a header or row is defined and Dispose/DisposeAsync is called on the row.

For reader nothing needs to be asynchronously disposed, so using does not require await. However, for SepWriter dispose may have to write/flush data to underlying TextWriter and hence it should be using DisposeAsync, so you must use await using.

To support cancellation many methods have overloads that accept a CancellationToken like the From*Async methods for creating a SepReader or for example NewRow for SepWriter. Consult Public API Reference for full set of available methods.

Additionally, both SepReaderOptions and SepWriterOptions feature the bool AsyncContinueOnCapturedContext option that is forwarded to internal ConfigureAwait calls, see the ConfigureAwait FAQ for details on that.

Limitations and Constraints

Sep is designed to be minimal and fast. As such, it has some limitations and constraints:

  • Comments # are not directly supported. You can skip a row by:
    foreach (var row in reader) { // Skip row if starts with # if (!row.Span.StartsWith("#")) { // ... } }
    This does not allow skipping lines before a header row starting with # though. In Example Catalogue a full example is given detailing how to skip lines before header.

Comparison Benchmarks

To investigate the performance of Sep it is compared to:

  • CsvHelper - the most commonly used CSV library with a staggering downloads downloads on NuGet. Fully featured and battle tested.
  • Sylvan - is well-known and has previously been shown to be the fastest CSV libraries for parsing (Sep changes that 😉).
  • ReadLine/WriteLine - basic naive implementations that read line by line and split on separator. While writing columns, separators and line endings directly. Does not handle quotes or similar correctly.

All benchmarks are run from/to memory either with:

  • StringReader or StreamReader + MemoryStream
  • StringWriter or StreamWriter + MemoryStream

This to avoid confounding factors from reading from or writing to disk.

When using StringReader/StringWriter each char counts as 2 bytes, when measuring throughput e.g. MB/s. When using StreamReader/StreamWriter content is UTF-8 encoded and each char typically counts as 1 byte, as content usually limited to 1 byte per char in UTF-8. Note that in .NET for TextReader and TextWriter data is converted to/from char, but for reading such conversion can often be just as fast as Memmove.

By default only StringReader/StringWriter results are shown, if a result is based on StreamReader/StreamWriter it will be called out. Usually, results for StreamReader/StreamWriter are in line with StringReader/StringWriter but with half the throughput due to 1 byte vs 2 bytes. For brevity they are not shown here.

For all benchmark results, Sep has been defined as the Baseline in BenchmarkDotNet. This means Ratio will be 1.00 for Sep. For the others Ratio will then show how many times faster Sep is than that. Or how many times more bytes are allocated in Alloc Ratio.

Disclaimer: Any comparison made is based on a number of preconditions and assumptions. Sep is a new library written from the ground up to use the latest and greatest features in .NET. CsvHelper has a long history and has to take into account backwards compatibility and still supporting older runtimes, so may not be able to easily utilize more recent features. Same goes for Sylvan. Additionally, Sep has a different feature set compared to the two. Performance is a feature, but not the only feature. Keep that in mind when evaluating results.

Runtime and Platforms

The following runtime is used for benchmarking:

  • NET 9.0.X

NOTE: Garbage Collection DATAS mode is disabled since this severely impacts (e.g. 1.7x slower) performance for some benchmarks due to the bursty accumulated allocations. That is, GarbageCollectionAdaptationMode is set to 0.

The following platforms are used for benchmarking:

  • AMD EPYC 7763 (Virtual) X64 Platform Information
    OS=Ubuntu 22.04.5 LTS (Jammy Jellyfish) AMD EPYC 7763, 1 CPU, 4 logical and 2 physical cores
  • AMD Ryzen 7 PRO 7840U (Laptop on battery) X64 Platform Information
    OS=Windows 11 (10.0.22631.4460/23H2/2023Update/SunValley3) AMD Ryzen 7 PRO 7840U w/ Radeon 780M Graphics, 1 CPU, 16 logical and 8 physical cores
  • AMD 5950X (Desktop) X64 Platform Information (no longer available)
    OS=Windows 10 (10.0.19044.2846/21H2/November2021Update) AMD Ryzen 9 5950X, 1 CPU, 32 logical and 16 physical cores
  • AMD 9950X (Desktop) X64 Platform Information
    OS=Windows 10 (10.0.19044.3086/21H2/November2021Update) AMD Ryzen 9 9950X, 1 CPU, 32 logical and 16 physical cores
  • Apple M1 (Virtual) ARM64 Platform Information
    OS=macOS Sonoma 14.7.1 (23H222) [Darwin 23.6.0] Apple M1 (Virtual), 1 CPU, 3 logical and 3 physical cores

Reader Comparison Benchmarks

The following reader scenarios are benchmarked:

Details for each can be found in the following. However, for each of these 3 different scopes are benchmarked to better assertain the low-level performance of each library and approach and what parts of the parsing consume the most time:

  • Row - for this scope only the row is enumerated. That is, for Sep all that is done is:
    foreach (var row in reader) { }
    this should capture parsing both row and columns but without accessing these. Note that some libraries (like Sylvan) will defer work for columns to when these are accessed.
  • Cols - for this scope all rows and all columns are enumerated. If possible columns are accessed as spans, if not as strings, which then might mean a string has to be allocated. That is, for Sep this is:
    foreach (var row in reader) { for (var i = 0; i < row.ColCount; i++) { var span = row[i].Span; } }
  • XYZ - finally the full scope is performed which is specific to each of the scenarios.

Additionally, as Sep supports multi-threaded parsing via ParallelEnumerate benchmarks results with _MT in the method name are multi-threaded. These show Sep provides unparalleled performance compared to any other CSV parser.

The overhead of Sep async support is also benchmarked and can be seen with _Async in the method name. Note that this is the absolute best case for async given there is no real IO involved and hence no actual asynchronous work or continuations (thus no Task allocations) since benchmarks run from memory only. This is fine as the main purpose of the benchmark is to gauge the overhead of the async code path.

NCsvPerf PackageAssets Reader Comparison Benchmarks

NCsvPerf from The fastest CSV parser in .NET is a benchmark which in Joel Verhagen own words was defined with:

My goal was to find the fastest low-level CSV parser. Essentially, all I wanted was a library that gave me a string[] for each line where each field in the line was an element in the array.

What is great about this work is it tests a whole of 35 different libraries and approaches to this. Providing a great overview of those and their performance on this specific scenario. Given Sylvan is the fastest of those it is used as the one to beat here, while CsvHelper is used to compare to the most commonly used library.

The source used for this benchmark PackageAssetsBench.cs is a PackageAssets.csv with NuGet package information in 25 columns with rows like:

75fcf875-017d-4579-bfd9-791d3e6767f0,2020-11-28T01:50:41.2449947+00:00,Akinzekeel.BlazorGrid,0.9.1-preview,2020-11-27T22:42:54.3100000+00:00,AvailableAssets,RuntimeAssemblies,,,net5.0,,,,,,lib/net5.0/BlazorGrid.dll,BlazorGrid.dll,.dll,lib,net5.0,.NETCoreApp,5.0.0.0,,,0.0.0.0 75fcf875-017d-4579-bfd9-791d3e6767f0,2020-11-28T01:50:41.2449947+00:00,Akinzekeel.BlazorGrid,0.9.1-preview,2020-11-27T22:42:54.3100000+00:00,AvailableAssets,CompileLibAssemblies,,,net5.0,,,,,,lib/net5.0/BlazorGrid.dll,BlazorGrid.dll,.dll,lib,net5.0,.NETCoreApp,5.0.0.0,,,0.0.0.0 75fcf875-017d-4579-bfd9-791d3e6767f0,2020-11-28T01:50:41.2449947+00:00,Akinzekeel.BlazorGrid,0.9.1-preview,2020-11-27T22:42:54.3100000+00:00,AvailableAssets,ResourceAssemblies,,,net5.0,,,,,,lib/net5.0/de/BlazorGrid.resources.dll,BlazorGrid.resources.dll,.dll,lib,net5.0,.NETCoreApp,5.0.0.0,,,0.0.0.0 75fcf875-017d-4579-bfd9-791d3e6767f0,2020-11-28T01:50:41.2449947+00:00,Akinzekeel.BlazorGrid,0.9.1-preview,2020-11-27T22:42:54.3100000+00:00,AvailableAssets,MSBuildFiles,,,any,,,,,,build/Microsoft.AspNetCore.StaticWebAssets.props,Microsoft.AspNetCore.StaticWebAssets.props,.props,build,any,Any,0.0.0.0,,,0.0.0.0 75fcf875-017d-4579-bfd9-791d3e6767f0,2020-11-28T01:50:41.2449947+00:00,Akinzekeel.BlazorGrid,0.9.1-preview,2020-11-27T22:42:54.3100000+00:00,AvailableAssets,MSBuildFiles,,,any,,,,,,build/Akinzekeel.BlazorGrid.props,Akinzekeel.BlazorGrid.props,.props,build,any,Any,0.0.0.0,,,0.0.0.0

For Scope = Asset the columns are parsed into a PackageAsset class, which consists of 25 properties of which 22 are strings. Each asset is accumulated into a List<PackageAsset>. Each column is accessed as a string regardless.

This means this benchmark is dominated by turning columns into strings for the decently fast parsers. Hence, the fastest libraries in this test employ string pooling. That is, basically a custom dictionary from ReadOnlySpan<char> to string, which avoids allocating a new string for repeated values. And as can be seen in the csv-file there are a lot of repeated values. Both Sylvan and CsvHelper do this in the benchmark. So does Sep and as with Sep this is an optional configuration that has to be explicitly enable. For Sep this means the reader is created with something like:

using var reader = Sep.Reader(o => o with { HasHeader = false, CreateToString = SepToString.PoolPerCol(maximumStringLength: 128), }) .From(CreateReader());

What is unique for Sep is that it allows defining a pool per column e.g. via SepToString.PoolPerCol(...). This is based on the fact that often each column has its own set of values or strings that may be repeated without any overlap to other columns. This also allows one to define per column specific handling of ToString behavior. Whether to pool or not. Or even to use a statically defined pool.

Sep supports unescaping via an option, see SepReaderOptions and Unescaping. Therefore, Sep has two methods being tested. The default Sep without unescaping and Sep_Unescape where unescaping is enabled. Note that only if there are quotes will there be any unescaping, but to support unescape one has to track extra state during parsing which means there is a slight cost no matter what, most notably for the Cols scope. Sep is still the fastest of all (by far in many cases).

PackageAssets Benchmark Results

The results below show Sep is the fastest .NET CSV Parser (for this benchmark on these platforms and machines 😀). While for pure parsing allocating only a fraction of the memory due to extensive use of pooling and the ArrayPool<T>.

This is in many aspects due to Sep having extremely optimized string pooling and optimized hashing of ReadOnlySpan<char>, and thus not really due the the csv-parsing itself, since that is not a big part of the time consumed. At least not for a decently fast csv-parser.

With ParallelEnumerate (MT) Sep is >2x faster than Sylvan and up to 9x faster than CsvHelper.

At the lowest level of enumerating rows only, that is csv parsing only, Sep hits a staggering 21 GB/s on 9950X. Single-threaded.

AMD.EPYC.7763 - PackageAssets Benchmark Results (Sep 0.12.0.0, Sylvan 1.4.3.0, CsvHelper 33.1.0.26)
MethodScopeRowsMeanRatioMBMB/sns/rowAllocatedAlloc Ratio
Sep______Row500003.531 ms1.00298236.470.61.01 KB1.00
Sep_AsyncRow500003.778 ms1.07297698.275.61.01 KB1.00
Sep_UnescapeRow500003.520 ms1.00298263.070.41.13 KB1.12
Sylvan___Row500004.298 ms1.22296766.886.07.65 KB7.59
ReadLine_Row5000021.890 ms6.20291328.7437.888608.23 KB87,921.34
CsvHelperRow5000064.318 ms18.2229452.21286.419.95 KB19.79
Sep______Cols500004.921 ms1.00295911.198.41.01 KB1.00
Sep_UnescapeCols500005.793 ms1.18295020.8115.91.01 KB1.00
Sylvan___Cols500008.024 ms1.63293625.1160.57.65 KB7.59
ReadLine_Cols5000023.332 ms4.74291246.6466.688608.23 KB87,921.34
CsvHelperCols50000101.802 ms20.6929285.72036.0445.6 KB442.15
Sep______Asset5000039.836 ms1.0029730.1796.713803.05 KB1.00
Sep_MT___Asset5000029.563 ms0.7429983.9591.313875.06 KB1.01
Sylvan___Asset5000047.912 ms1.2029607.1958.213962.03 KB1.01
ReadLine_Asset50000131.577 ms3.3129221.12631.5102133.63 KB7.40
CsvHelperAsset50000122.181 ms3.0729238.12443.613971.42 KB1.01
Sep______Asset1000000864.069 ms1.00581673.4864.1266667.16 KB1.00
Sep_MT___Asset1000000516.021 ms0.605811127.6516.0276325.84 KB1.04
Sylvan___Asset10000001,011.286 ms1.17581575.41011.3266824.48 KB1.00
ReadLine_Asset10000002,850.125 ms3.30581204.22850.12038834.76 KB7.65
CsvHelperAsset10000002,579.496 ms2.99581225.62579.5266840.54 KB1.00
AMD.Ryzen.7.PRO.7840U.w.Radeon.780M - PackageAssets Benchmark Results (Sep 0.12.0.0, Sylvan 1.4.3.0, CsvHelper 33.1.0.26)
MethodScopeRowsMeanRatioMBMB/sns/rowAllocatedAlloc Ratio
Sep______Row500003.501 ms1.00298334.370.01.01 KB1.00
Sep_AsyncRow500003.748 ms1.07297785.175.01.01 KB1.00
Sep_UnescapeRow500003.489 ms1.00298364.769.81.01 KB1.00
Sylvan___Row500004.436 ms1.27296578.688.77.65 KB7.59
ReadLine_Row5000018.126 ms5.18291609.9362.588608.23 KB87,921.34
CsvHelperRow5000065.367 ms18.6929446.41307.319.95 KB19.79
Sep______Cols500004.800 ms1.00296079.796.01.01 KB1.00
Sep_UnescapeCols500005.952 ms1.24294902.5119.01.01 KB1.00
Sylvan___Cols500008.572 ms1.79293404.3171.47.65 KB7.59
ReadLine_Cols5000019.182 ms4.00291521.3383.688608.23 KB87,921.34
CsvHelperCols50000108.414 ms22.5929269.22168.3445.6 KB442.15
Sep______Asset5000052.283 ms1.0029558.11045.713802.65 KB1.00
Sep_MT___Asset5000034.441 ms0.6629847.3688.813913.24 KB1.01
Sylvan___Asset5000053.960 ms1.0429540.81079.213962.29 KB1.01
ReadLine_Asset50000210.735 ms4.0429138.54214.7102133.96 KB7.40
CsvHelperAsset50000131.644 ms2.5329221.72632.913970.83 KB1.01
Sep______Asset1000000978.280 ms1.00583596.7978.3266668.88 KB1.00
Sep_MT___Asset1000000515.844 ms0.535831131.7515.8267776.55 KB1.00
Sylvan___Asset10000001,130.594 ms1.16583516.41130.6266825.13 KB1.00
ReadLine_Asset10000003,155.567 ms3.23583185.03155.62038835.23 KB7.65
CsvHelperAsset10000002,669.767 ms2.73583218.72669.8266844.99 KB1.00
AMD.Ryzen.9.5950X - PackageAssets Benchmark Results (Sep 0.9.0.0, Sylvan 1.3.9.0, CsvHelper 33.0.1.24)
MethodScopeRowsMeanRatioMBMB/sns/rowAllocatedAlloc Ratio
Sep______Row500002.230 ms1.002913088.444.61.09 KB1.00
Sep_AsyncRow500002.379 ms1.072912264.047.61.02 KB0.93
Sep_UnescapeRow500002.305 ms1.032912657.646.11.02 KB0.93
Sylvan___Row500002.993 ms1.33299750.259.97.65 KB7.52
ReadLine_Row5000012.106 ms5.36292410.5242.188608.25 KB87,077.59
CsvHelperRow5000043.313 ms19.1929673.7866.320.04 KB19.69
Sep______Cols500003.211 ms1.00299089.364.21.02 KB1.00
Sep_UnescapeCols500003.845 ms1.20297589.176.91.02 KB1.00
Sylvan___Cols500005.065 ms1.58295760.9101.37.66 KB7.52
ReadLine_Cols5000012.850 ms4.00292270.9257.088608.25 KB86,910.78
CsvHelperCols5000068.999 ms21.4929422.91380.0445.85 KB437.31
Sep______Asset5000033.615 ms1.0029868.1672.313802.47 KB1.00
Sep_MT___Asset5000020.231 ms0.60291442.4404.613992.1 KB1.01
Sylvan___Asset5000034.762 ms1.0329839.5695.213962.2 KB1.01
ReadLine_Asset5000097.204 ms2.8929300.21944.1102133.9 KB7.40
CsvHelperAsset5000083.550 ms2.4929349.31671.013970.66 KB1.01
Sep______Asset1000000629.552 ms1.00583927.3629.6266669.13 KB1.00
Sep_MT___Asset1000000261.089 ms0.415832236.0261.1267793.45 KB1.00
Sylvan___Asset1000000761.171 ms1.21583767.0761.2266825.09 KB1.00
ReadLine_Asset10000001,636.526 ms2.60583356.71636.52038835.59 KB7.65
CsvHelperAsset10000001,754.461 ms2.79583332.71754.5266833.16 KB1.00
AMD.Ryzen.9.9950X - PackageAssets Benchmark Results (Sep 0.12.0.0, Sylvan 1.4.3.0, CsvHelper 33.1.0.26)
MethodScopeRowsMeanRatioMBMB/sns/rowAllocatedAlloc Ratio
Sep______Row500001.385 ms1.002921072.527.71.01 KB1.00
Sep_AsyncRow500001.518 ms1.102919225.730.41.01 KB1.00
Sep_UnescapeRow500001.393 ms1.012920942.627.91.01 KB1.00
Sylvan___Row500001.885 ms1.362915484.537.77.65 KB7.59
ReadLine_Row500007.885 ms5.69293701.1157.788608.23 KB87,921.34
CsvHelperRow5000023.848 ms17.22291223.6477.019.95 KB19.79
Sep______Cols500002.010 ms1.002914520.040.21.01 KB1.00
Sep_UnescapeCols500002.366 ms1.182912332.147.31.01 KB1.00
Sylvan___Cols500003.188 ms1.59299152.363.87.65 KB7.59
ReadLine_Cols500008.349 ms4.15293495.3167.088608.23 KB87,921.34
CsvHelperCols5000043.794 ms21.7929666.3875.9445.61 KB442.15
Sep______Asset5000024.029 ms1.00291214.4480.613802.35 KB1.00
Sep_MT___Asset5000014.474 ms0.60292016.1289.513994.5 KB1.01
Sylvan___Asset5000025.166 ms1.05291159.6503.313962.14 KB1.01
ReadLine_Asset5000078.997 ms3.2929369.41579.9102133.85 KB7.40
CsvHelperAsset5000054.192 ms2.2629538.51083.813973.22 KB1.01
Sep______Asset1000000441.913 ms1.005831321.0441.9266667.27 KB1.00
Sep_MT___Asset1000000186.231 ms0.425833134.7186.2268775.45 KB1.01
Sylvan___Asset1000000520.745 ms1.185831121.1520.7266824.38 KB1.00
ReadLine_Asset10000001,377.806 ms3.12583423.71377.82038834.84 KB7.65
CsvHelperAsset10000001,173.256 ms2.65583497.61173.3266840.63 KB1.00
Apple.M1.(Virtual) - PackageAssets Benchmark Results (Sep 0.12.0.0, Sylvan 1.4.3.0, CsvHelper 33.1.0.26)
MethodScopeRowsMeanRatioMBMB/sns/rowAllocatedAlloc Ratio
Sep______Row500003.972 ms1.01297323.279.4952 B1.00
Sep_AsyncRow500003.992 ms1.01297286.979.8952 B1.00
Sep_UnescapeRow500004.902 ms1.24295933.798.0952 B1.00
Sylvan___Row5000027.633 ms7.01291052.6552.76692 B7.03
ReadLine_Row5000021.068 ms5.34291380.6421.490734824 B95,309.69
CsvHelperRow5000058.651 ms14.8829495.91173.020424 B21.45
Sep______Cols500004.505 ms1.00296456.190.1952 B1.00
Sep_UnescapeCols500005.077 ms1.13295729.1101.5952 B1.00
Sylvan___Cols5000029.637 ms6.5829981.4592.76692 B7.03
ReadLine_Cols5000025.961 ms5.77291120.4519.290734824 B95,309.69
CsvHelperCols5000070.982 ms15.7629409.81419.6456296 B479.30
Sep______Asset5000039.331 ms1.0129739.5786.614133358 B1.00
Sep_MT___Asset5000032.270 ms0.8329901.3645.414228814 B1.01
Sylvan___Asset5000058.127 ms1.4929500.41162.514295768 B1.01
ReadLine_Asset50000115.274 ms2.9529252.32305.5104585064 B7.40
CsvHelperAsset5000092.185 ms2.3629315.51843.714305450 B1.01
Sep______Asset1000000752.281 ms1.00581773.5752.3273067192 B1.00
Sep_MT___Asset1000000804.179 ms1.07581723.6804.2287567112 B1.05
Sylvan___Asset10000001,410.084 ms1.88581412.71410.1273226864 B1.00
ReadLine_Asset10000003,592.746 ms4.79581162.03592.72087766752 B7.65
CsvHelperAsset10000002,322.007 ms3.10581250.62322.0273241184 B1.00
Cobalt.100 - PackageAssets Benchmark Results (Sep 0.12.0.0, Sylvan 1.4.3.0, CsvHelper 33.1.0.26)
MethodScopeRowsMeanRatioMBMB/sns/rowAllocatedAlloc Ratio
Sep______Row500005.786 ms1.00295043.2115.7952 B1.00
Sep_AsyncRow500005.919 ms1.02294929.9118.4952 B1.00
Sep_UnescapeRow500005.527 ms0.96295280.2110.5952 B1.00
Sylvan___Row5000021.097 ms3.65291383.2421.96653 B6.99
ReadLine_Row5000020.407 ms3.53291430.0408.190734824 B95,309.69
CsvHelperRow5000054.870 ms9.4929531.81097.420424 B21.45
Sep______Cols500007.355 ms1.00293967.3147.1952 B1.00
Sep_UnescapeCols500007.875 ms1.07293705.7157.5952 B1.00
Sylvan___Cols5000024.954 ms3.39291169.4499.16656 B6.99
ReadLine_Cols5000020.826 ms2.83291401.2416.590734827 B95,309.69
CsvHelperCols5000088.817 ms12.0829328.61776.3456368 B479.38
Sep______Asset5000031.305 ms1.0029932.2626.114132992 B1.00
Sep_MT___Asset5000013.853 ms0.44292106.5277.114184144 B1.00
Sylvan___Asset5000056.747 ms1.8129514.21134.914295595 B1.01
ReadLine_Asset50000127.959 ms4.0929228.12559.2104584112 B7.40
CsvHelperAsset5000098.423 ms3.1429296.51968.514305310 B1.01
Sep______Asset1000000790.081 ms1.00583738.9790.1273063584 B1.00
Sep_MT___Asset1000000376.771 ms0.485831549.4376.8282250016 B1.03
Sylvan___Asset10000001,234.977 ms1.56583472.71235.0273225232 B1.00
ReadLine_Asset10000002,851.876 ms3.61583204.72851.92087764592 B7.65
CsvHelperAsset10000002,133.327 ms2.70583273.62133.3273234944 B1.00
PackageAssets Benchmark Results (SERVER GC)

The package assets benchmark (Scope Asset) has a very high base load in the form of the accumulated instances of PackageAsset and since Sep is so fast the GC becomes a significant bottleneck for the benchmark, especially for multi-threaded parsing. Switching to SERVER GC can, therefore, provide significant speedup as can be seen below.

With ParallelEnumerate and server GC Sep is >4x faster than Sylvan and up to 18x faster than CsvHelper. Breaking 8 GB/s parsing speed on package assets on 9950X.

AMD.EPYC.7763 - PackageAssets Benchmark Results (SERVER GC) (Sep 0.12.0.0, Sylvan 1.4.3.0, CsvHelper 33.1.0.26)
MethodScopeRowsMeanRatioMBMB/sns/rowAllocatedAlloc Ratio
Sep______Asset5000033.24 ms1.0029874.9664.913.48 MB1.00
Sep_MT___Asset5000016.93 ms0.51291718.1338.613.54 MB1.00
Sylvan___Asset5000041.02 ms1.2329709.1820.413.63 MB1.01
ReadLine_Asset5000059.34 ms1.7929490.11186.999.74 MB7.40
CsvHelperAsset50000114.45 ms3.4429254.12289.013.64 MB1.01
Sep______Asset1000000656.08 ms1.00581886.9656.1260.41 MB1.00
Sep_MT___Asset1000000333.94 ms0.515811742.5333.9268.8 MB1.03
Sylvan___Asset1000000824.37 ms1.26581705.8824.4260.57 MB1.00
ReadLine_Asset10000001,231.05 ms1.88581472.71231.11991.04 MB7.65
CsvHelperAsset10000002,342.51 ms3.57581248.42342.5260.58 MB1.00
AMD.Ryzen.7.PRO.7840U.w.Radeon.780M - PackageAssets Benchmark Results (SERVER GC) (Sep 0.12.0.0, Sylvan 1.4.3.0, CsvHelper 33.1.0.26)
MethodScopeRowsMeanRatioMBMB/sns/rowAllocatedAlloc Ratio
Sep______Asset5000035.630 ms1.0029819.0712.613.48 MB1.00
Sep_MT___Asset500008.892 ms0.25293281.6177.813.57 MB1.01
Sylvan___Asset5000038.901 ms1.0929750.1778.013.63 MB1.01
ReadLine_Asset5000043.945 ms1.2329664.0878.999.74 MB7.40
CsvHelperAsset50000116.596 ms3.2729250.32331.913.64 MB1.01
Sep______Asset1000000654.638 ms1.00583891.8654.6260.41 MB1.00
Sep_MT___Asset1000000244.949 ms0.375832383.3244.9262.32 MB1.01
Sylvan___Asset1000000825.727 ms1.26583707.0825.7260.57 MB1.00
ReadLine_Asset1000000968.707 ms1.48583602.6968.71991.04 MB7.65
CsvHelperAsset10000002,364.922 ms3.62583246.92364.9260.58 MB1.00
AMD.Ryzen.9.5950X - PackageAssets Benchmark Results (SERVER GC) (Sep 0.9.0.0, Sylvan 1.3.9.0, CsvHelper 33.0.1.24)
MethodScopeRowsMeanRatioMBMB/sns/rowAllocatedAlloc Ratio
Sep______Asset5000020.951 ms1.00291392.9419.013.48 MB1.00
Sep_MT___Asset500006.614 ms0.32294411.8132.313.64 MB1.01
Sylvan___Asset5000027.761 ms1.33291051.2555.213.63 MB1.01
ReadLine_Asset5000033.516 ms1.6029870.7670.399.74 MB7.40
CsvHelperAsset5000077.007 ms3.6829378.91540.113.64 MB1.01
Sep______Asset1000000432.887 ms1.005831348.6432.9260.41 MB1.00
Sep_MT___Asset1000000119.430 ms0.285834888.1119.4261.39 MB1.00
Sylvan___Asset1000000559.550 ms1.295831043.3559.6260.57 MB1.00
ReadLine_Asset1000000573.637 ms1.335831017.7573.61991.05 MB7.65
CsvHelperAsset10000001,537.602 ms3.55583379.71537.6260.58 MB1.00
AMD.Ryzen.9.9950X - PackageAssets Benchmark Results (SERVER GC) (Sep 0.12.0.0, Sylvan 1.4.3.0, CsvHelper 33.1.0.26)
MethodScopeRowsMeanRatioMBMB/sns/rowAllocatedAlloc Ratio
Sep______Asset5000014.152 ms1.00292062.0283.013.48 MB1.00
Sep_MT___Asset500003.460 ms0.24298434.169.213.65 MB1.01
Sylvan___Asset5000018.113 ms1.28291611.1362.313.63 MB1.01
ReadLine_Asset5000018.960 ms1.34291539.1379.299.74 MB7.40
CsvHelperAsset5000048.971 ms3.4629595.9979.413.64 MB1.01
Sep______Asset1000000289.503 ms1.005832016.5289.5260.41 MB1.00
Sep_MT___Asset100000058.678 ms0.205839949.058.7261.63 MB1.00
Sylvan___Asset1000000375.349 ms1.305831555.3375.3260.57 MB1.00
ReadLine_Asset1000000364.651 ms1.265831600.9364.71991.04 MB7.65
CsvHelperAsset1000000999.550 ms3.45583584.0999.5260.58 MB1.00
Apple.M1.(Virtual) - PackageAssets Benchmark Results (SERVER GC) (Sep 0.12.0.0, Sylvan 1.4.3.0, CsvHelper 33.1.0.26)
MethodScopeRowsMeanRatioMBMB/sns/rowAllocatedAlloc Ratio
Sep______Asset5000031.64 ms1.0129919.3632.813.48 MB1.00
Sep_MT___Asset5000023.46 ms0.75291239.8469.213.65 MB1.01
Sylvan___Asset5000061.59 ms1.9629472.21231.813.63 MB1.01
ReadLine_Asset5000053.87 ms1.7129539.91077.499.74 MB7.40
CsvHelperAsset50000109.28 ms3.4829266.22185.613.64 MB1.01
Sep______Asset1000000689.69 ms1.00581843.7689.7260.41 MB1.00
Sep_MT___Asset1000000311.19 ms0.455811869.8311.2270.88 MB1.04
Sylvan___Asset10000001,380.63 ms2.01581421.51380.6260.57 MB1.00
ReadLine_Asset10000002,073.15 ms3.02581280.72073.11991.05 MB7.65
CsvHelperAsset10000002,448.67 ms3.57581237.62448.7260.58 MB1.00
Cobalt.100 - PackageAssets Benchmark Results (SERVER GC) (Sep 0.12.0.0, Sylvan 1.4.3.0, CsvHelper 33.1.0.26)
MethodScopeRowsMeanRatioMBMB/sns/rowAllocatedAlloc Ratio
Sep______Asset5000032.59 ms1.0029895.3651.913.48 MB1.00
Sep_MT___Asset5000011.62 ms0.36292510.8232.413.53 MB1.00
Sylvan___Asset5000054.88 ms1.6829531.81097.513.63 MB1.01
ReadLine_Asset5000049.51 ms1.5229589.4990.299.74 MB7.40
CsvHelperAsset5000099.62 ms3.0629292.91992.413.64 MB1.01
Sep______Asset1000000650.92 ms1.00583896.9650.9260.41 MB1.00
Sep_MT___Asset1000000200.74 ms0.315832908.2200.7266.53 MB1.02
Sylvan___Asset10000001,104.81 ms1.70583528.41104.8260.57 MB1.00
ReadLine_Asset10000001,025.26 ms1.58583569.41025.31991.04 MB7.65
CsvHelperAsset10000002,089.05 ms3.21583279.42089.1260.58 MB1.00
PackageAssets with Quotes Benchmark Results

NCsvPerf does not examine performance in the face of quotes in the csv. This is relevant since some libraries like Sylvan will revert to a slower (not SIMD vectorized) parsing code path if it encounters quotes. Sep was designed to always use SIMD vectorization no matter what.

Since there are two extra chars to handle per column, it does have a significant impact on performance, no matter what though. This is expected when looking at the numbers. For each row of 25 columns, there are 24 separators (here ,) and one set of line endings (here \r\n). That's 26 characters. Adding quotes around each of the 25 columns will add 50 characters or almost triple the total to 76.

AMD.EPYC.7763 - PackageAssets with Quotes Benchmark Results (Sep 0.12.0.0, Sylvan 1.4.3.0, CsvHelper 33.1.0.26)
MethodScopeRowsMeanRatioMBMB/sns/rowAllocatedAlloc Ratio
Sep______Row5000010.81 ms1.00333079.3216.21.01 KB1.00
Sep_AsyncRow5000011.24 ms1.04332962.1224.71.01 KB1.00
Sep_UnescapeRow5000011.45 ms1.06332906.6229.01.01 KB1.00
Sylvan___Row5000025.19 ms2.33331321.3503.87.66 KB7.60
ReadLine_Row5000026.33 ms2.44331263.9526.6108778.73 KB107,935.48
CsvHelperRow5000078.33 ms7.2533424.91566.620.02 KB19.86
Sep______Cols5000013.13 ms1.00332535.3262.51.01 KB1.00
Sep_UnescapeCols5000013.97 ms1.06332382.3279.41.01 KB1.00
Sylvan___Cols5000028.21 ms2.15331179.7564.27.67 KB7.61
ReadLine_Cols5000027.63 ms2.10331204.5552.6108778.73 KB107,935.48
CsvHelperCols50000106.12 ms8.0833313.62122.4445.68 KB442.22
Sep______Asset5000046.78 ms1.0033711.5935.613802.41 KB1.00
Sep_MT___Asset5000030.32 ms0.65331097.6606.513869.65 KB1.00
Sylvan___Asset5000069.34 ms1.4833480.01386.713962.04 KB1.01
ReadLine_Asset50000150.28 ms3.2133221.53005.6122304.69 KB8.86
CsvHelperAsset50000126.16 ms2.7033263.82523.213971.27 KB1.01
Sep______Asset1000000973.20 ms1.00665684.1973.2266667.22 KB1.00
Sep_MT___Asset1000000589.97 ms0.616651128.5590.0271570.43 KB1.02
Sylvan___Asset10000001,404.92 ms1.44665473.91404.9266824.36 KB1.00
ReadLine_Asset10000003,386.92 ms3.48665196.63386.92442318.06 KB9.16
CsvHelperAsset10000002,553.57 ms2.62665260.72553.6266834.87 KB1.00
AMD.Ryzen.7.PRO.7840U.w.Radeon.780M - PackageAssets with Quotes Benchmark Results (Sep 0.12.0.0, Sylvan 1.4.3.0, CsvHelper 33.1.0.26)
MethodScopeRowsMeanRatioMBMB/sns/rowAllocatedAlloc Ratio
Sep______Row5000011.228 ms1.00332972.8224.61.01 KB1.00
Sep_AsyncRow500009.916 ms0.88333365.9198.31.01 KB1.00
Sep_UnescapeRow500009.953 ms0.89333353.4199.11.01 KB1.00
Sylvan___Row5000023.829 ms2.12331400.7476.67.66 KB7.60
ReadLine_Row5000021.909 ms1.95331523.4438.2108778.73 KB107,935.48
CsvHelperRow5000071.571 ms6.3833466.41431.419.95 KB19.79
Sep______Cols5000012.798 ms1.00332608.0256.01.01 KB1.00
Sep_UnescapeCols5000013.689 ms1.07332438.2273.81.01 KB1.00
Sylvan___Cols5000027.287 ms2.13331223.2545.77.67 KB7.61
ReadLine_Cols5000023.201 ms1.81331438.6464.0108778.73 KB107,935.48
CsvHelperCols50000104.298 ms8.1533320.02086.0445.6 KB442.15
Sep______Asset5000055.957 ms1.0033596.51119.113802.68 KB1.00
Sep_MT___Asset5000044.668 ms0.8033747.2893.413934.89 KB1.01
Sylvan___Asset5000068.353 ms1.2233488.31367.113961.88 KB1.01
ReadLine_Asset50000260.030 ms4.6533128.45200.6122304.52 KB8.86
CsvHelperAsset50000127.992 ms2.2933260.82559.813971.32 KB1.01
Sep______Asset10000001,145.307 ms1.00667583.01145.3266673.49 KB1.00
Sep_MT___Asset1000000696.277 ms0.61667959.0696.3267979.84 KB1.00
Sylvan___Asset10000001,499.974 ms1.31667445.11500.0266827.47 KB1.00
ReadLine_Asset10000004,060.701 ms3.55667164.44060.72442318 KB9.16
CsvHelperAsset10000002,601.519 ms2.27667256.72601.5266839.95 KB1.00
AMD.Ryzen.9.5950X - PackageAssets with Quotes Benchmark Results (Sep 0.9.0.0, Sylvan 1.3.9.0, CsvHelper 33.0.1.24)
MethodScopeRowsMeanRatioMBMB/sns/rowAllocatedAlloc Ratio
Sep______Row500007.046 ms1.00334737.2140.91.04 KB1.00
Sep_AsyncRow500008.137 ms1.15334101.8162.71.04 KB1.00
Sep_UnescapeRow500007.473 ms1.06334466.7149.51.04 KB1.00
Sylvan___Row5000017.571 ms2.38331899.5351.47.69 KB7.41
ReadLine_Row5000014.336 ms1.94332328.2286.7108778.75 KB104,689.33
CsvHelperRow5000052.672 ms7.1233633.71053.420.05 KB19.29
Sep______Cols500008.126 ms1.00334107.5162.51.04 KB1.00
Sep_UnescapeCols500009.748 ms1.20333424.0195.01.05 KB1.01
Sylvan___Cols5000020.503 ms2.52331628.0410.17.7 KB7.39
ReadLine_Cols5000016.513 ms2.03332021.3330.3108778.76 KB104,394.99
CsvHelperCols5000074.224 ms9.1333449.71484.5445.85 KB427.88
Sep______Asset5000039.523 ms1.0033844.5790.513802.63 KB1.00
Sep_MT___Asset5000023.386 ms0.59331427.2467.713981.76 KB1.01
Sylvan___Asset5000050.803 ms1.2933657.01016.113962.08 KB1.01
ReadLine_Asset50000114.306 ms2.8933292.02286.1122304.45 KB8.86
CsvHelperAsset5000088.786 ms2.2533375.91775.713970.43 KB1.01
Sep______Asset1000000752.681 ms1.00667887.1752.7266669 KB1.00
Sep_MT___Asset1000000377.733 ms0.506671767.7377.7267992.5 KB1.00
Sylvan___Asset10000001,091.345 ms1.45667611.81091.3266825.09 KB1.00
ReadLine_Asset10000002,615.390 ms3.47667255.32615.42442319.06 KB9.16
CsvHelperAsset10000001,756.409 ms2.33667380.21756.4266839.53 KB1.00
AMD.Ryzen.9.9950X - PackageAssets with Quotes Benchmark Results (Sep 0.12.0.0, Sylvan 1.4.3.0, CsvHelper 33.1.0.26)
MethodScopeRowsMeanRatioMBMB/sns/rowAllocatedAlloc Ratio
Sep______Row500004.288 ms1.00337783.585.81.01 KB1.00
Sep_AsyncRow500005.226 ms1.22336386.4104.51.01 KB1.00
Sep_UnescapeRow500004.170 ms0.97338004.383.41.15 KB1.14
Sylvan___Row5000010.286 ms2.40333245.1205.77.65 KB7.59
ReadLine_Row500009.464 ms2.21333526.9189.3108778.73 KB107,935.48
CsvHelperRow5000027.086 ms6.32331232.3541.719.95 KB19.79
Sep______Cols500005.100 ms1.00336544.9102.01.01 KB1.00
Sep_UnescapeCols500005.496 ms1.08336073.5109.91.01 KB1.00
Sylvan___Cols5000011.899 ms2.33332805.1238.07.66 KB7.60
ReadLine_Cols5000010.023 ms1.97333330.1200.5108778.73 KB107,935.48
CsvHelperCols5000040.244 ms7.8933829.4804.9445.61 KB442.15
Sep______Asset5000028.037 ms1.00331190.5560.713802.3 KB1.00
Sep_MT___Asset5000017.037 ms0.61331959.1340.713989.51 KB1.01
Sylvan___Asset5000031.020 ms1.11331076.0620.413962.02 KB1.01
ReadLine_Asset5000095.065 ms3.3933351.11901.3122304.75 KB8.86
CsvHelperAsset5000051.339 ms1.8333650.11026.813970.75 KB1.01
Sep______Asset1000000519.607 ms1.006671285.0519.6266667.37 KB1.00
Sep_MT___Asset1000000221.654 ms0.436673012.4221.7270630.1 KB1.01
Sylvan___Asset1000000703.908 ms1.35667948.6703.9266824.38 KB1.00
ReadLine_Asset10000001,870.691 ms3.60667356.91870.72442318.59 KB9.16
CsvHelperAsset10000001,097.942 ms2.11667608.11097.9266832.53 KB1.00
Apple.M1.(Virtual) - PackageAssets with Quotes Benchmark Results (Sep 0.12.0.0, Sylvan 1.4.3.0, CsvHelper 33.1.0.26)
MethodScopeRowsMeanRatioMBMB/sns/rowAllocatedAlloc Ratio
Sep______Row5000010.004 ms1.01333326.8200.1952 B1.00
Sep_AsyncRow500008.591 ms0.86333874.3171.8952 B1.00
Sep_UnescapeRow500007.763 ms0.78334287.5155.3952 B1.00
Sylvan___Row5000023.401 ms2.36331422.2468.06692 B7.03
ReadLine_Row5000027.778 ms2.80331198.1555.6111389416 B117,005.69
CsvHelperRow5000053.094 ms5.3433626.91061.920424 B21.45
Sep______Cols5000011.885 ms1.01332800.2237.7952 B1.00
Sep_UnescapeCols5000012.821 ms1.09332596.0256.4952 B1.00
Sylvan___Cols5000027.213 ms2.31331223.0544.36692 B7.03
ReadLine_Cols5000023.611 ms2.00331409.6472.2111389416 B117,005.69
CsvHelperCols5000092.689 ms7.8633359.11853.8456296 B479.30
Sep______Asset5000040.423 ms1.0033823.3808.514134213 B1.00
Sep_MT___Asset5000036.395 ms0.9033914.5727.914211028 B1.01
Sylvan___Asset5000087.081 ms2.1633382.21741.614295952 B1.01
ReadLine_Asset50000135.098 ms3.3533246.42702.0125239776 B8.86
CsvHelperAsset5000089.705 ms2.2333371.01794.114305304 B1.01
Sep______Asset10000001,023.915 ms1.01665650.21023.9273066968 B1.00
Sep_MT___Asset1000000901.079 ms0.89665738.9901.1285049448 B1.04
Sylvan___Asset10000001,455.283 ms1.44665457.51455.3273232840 B1.00
ReadLine_Asset10000004,628.378 ms4.58665143.94628.42500933560 B9.16
CsvHelperAsset10000002,299.950 ms2.28665289.52299.9273242120 B1.00
Cobalt.100 - PackageAssets with Quotes Benchmark Results (Sep 0.12.0.0, Sylvan 1.4.3.0, CsvHelper 33.1.0.26)
MethodScopeRowsMeanRatioMBMB/sns/rowAllocatedAlloc Ratio
Sep______Row5000011.06 ms1.00333017.0221.3953 B1.00
Sep_AsyncRow5000011.38 ms1.03332934.3227.5954 B1.00
Sep_UnescapeRow5000011.28 ms1.02332958.1225.7954 B1.00
Sylvan___Row5000023.17 ms2.09331440.4463.46654 B6.98
ReadLine_Row5000024.39 ms2.20331368.6487.8111389416 B116,882.91
CsvHelperRow5000063.45 ms5.7433526.01269.020424 B21.43
Sep______Cols5000012.67 ms1.00332634.1253.4952 B1.00
Sep_UnescapeCols5000013.86 ms1.09332408.9277.1954 B1.00
Sylvan___Cols5000027.54 ms2.17331211.8550.96657 B6.99
ReadLine_Cols5000024.94 ms1.97331338.1498.9111389419 B117,005.69
CsvHelperCols5000097.05 ms7.6633343.91941.0456368 B479.38
Sep______Asset5000038.12 ms1.0033875.5762.414132992 B1.00
Sep_MT___Asset5000015.19 ms0.40332198.0303.714190126 B1.00
Sylvan___Asset5000058.84 ms1.5433567.31176.814295595 B1.01
ReadLine_Asset50000135.98 ms3.5733245.52719.6125238788 B8.86
CsvHelperAsset50000106.50 ms2.7933313.42130.114305310 B1.01
Sep______Asset1000000919.60 ms1.00667726.1919.6273063640 B1.00
Sep_MT___Asset1000000392.61 ms0.436671700.7392.6275587208 B1.01
Sylvan___Asset10000001,303.94 ms1.42667512.11303.9273225360 B1.00
ReadLine_Asset10000003,503.86 ms3.81667190.63503.92500932192 B9.16
CsvHelperAsset10000002,309.99 ms2.51667289.12310.0273236680 B1.00
PackageAssets with Quotes Benchmark Results (SERVER GC)

Here again are benchmark results with server garbage collection, which provides significant speedup over workstation garbage collection.

AMD.EPYC.7763 - PackageAssets with Quotes Benchmark Results (SERVER GC) (Sep 0.12.0.0, Sylvan 1.4.3.0, CsvHelper 33.1.0.26)
MethodScopeRowsMeanRatioMBMB/sns/rowAllocatedAlloc Ratio
Sep______Asset5000037.82 ms1.0033880.1756.313.48 MB1.00
Sep_MT___Asset5000019.95 ms0.53331668.2399.013.53 MB1.00
Sylvan___Asset5000060.86 ms1.6133546.81217.213.63 MB1.01
ReadLine_Asset5000065.12 ms1.7233511.11302.3119.44 MB8.86
CsvHelperAsset50000117.65 ms3.1133282.92353.013.64 MB1.01
Sep______Asset1000000814.18 ms1.00665817.8814.2260.41 MB1.00
Sep_MT___Asset1000000420.01 ms0.526651585.2420.0262.55 MB1.01
Sylvan___Asset10000001,275.65 ms1.57665521.91275.6260.57 MB1.00
ReadLine_Asset10000001,362.68 ms1.67665488.61362.72385.07 MB9.16
CsvHelperAsset10000002,362.46 ms2.90665281.82362.5260.58 MB1.00
AMD.Ryzen.7.PRO.7840U.w.Radeon.780M - PackageAssets with Quotes Benchmark Results (SERVER GC) (Sep 0.12.0.0, Sylvan 1.4.3.0, CsvHelper 33.1.0.26)
MethodScopeRowsMeanRatioMBMB/sns/rowAllocatedAlloc Ratio
Sep______Asset5000039.09 ms1.0033854.0781.713.48 MB1.00
Sep_MT___Asset5000025.90 ms0.66331288.9517.913.58 MB1.01
Sylvan___Asset5000059.92 ms1.5333557.01198.413.63 MB1.01
ReadLine_Asset5000060.27 ms1.5433553.81205.4119.44 MB8.86
CsvHelperAsset50000111.54 ms2.8533299.22230.813.64 MB1.01
Sep______Asset1000000810.33 ms1.00667824.0810.3260.41 MB1.00
Sep_MT___Asset1000000433.80 ms0.546671539.2433.8261.43 MB1.00
Sylvan___Asset10000001,216.78 ms1.50667548.81216.8260.57 MB1.00
ReadLine_Asset10000001,079.99 ms1.33667618.31080.02385.07 MB9.16
CsvHelperAsset10000002,275.20 ms2.81667293.52275.2260.58 MB1.00
AMD.Ryzen.9.5950X - PackageAssets with Quotes Benchmark Results (SERVER GC) (Sep 0.9.0.0, Sylvan 1.3.9.0, CsvHelper 33.0.1.24)
MethodScopeRowsMeanRatioMBMB/sns/rowAllocatedAlloc Ratio
Sep______Asset5000026.42 ms1.00331263.1528.513.48 MB1.00
Sep_MT___Asset5000011.53 ms0.44332894.1230.713.64 MB1.01
Sylvan___Asset5000043.05 ms1.6333775.3861.113.63 MB1.01
ReadLine_Asset5000037.30 ms1.4133894.8746.0119.44 MB8.86
CsvHelperAsset5000078.91 ms2.9933423.01578.113.64 MB1.01
Sep______Asset1000000538.48 ms1.006671240.0538.5260.43 MB1.00
Sep_MT___Asset1000000213.29 ms0.406673130.5213.3261.37 MB1.00
Sylvan___Asset1000000879.04 ms1.63667759.6879.0260.57 MB1.00
ReadLine_Asset1000000642.57 ms1.196671039.1642.62385.07 MB9.16
CsvHelperAsset10000001,598.79 ms2.97667417.61598.8260.58 MB1.00
AMD.Ryzen.9.9950X - PackageAssets with Quotes Benchmark Results (SERVER GC) (Sep 0.12.0.0, Sylvan 1.4.3.0, CsvHelper 33.1.0.26)
MethodScopeRowsMeanRatioMBMB/sns/rowAllocatedAlloc Ratio
Sep______Asset5000017.792 ms1.00331876.0355.813.48 MB1.00
Sep_MT___Asset500005.863 ms0.33335692.8117.313.64 MB1.01
Sylvan___Asset5000027.020 ms1.52331235.3540.413.63 MB1.01
ReadLine_Asset5000022.191 ms1.25331504.1443.8119.44 MB8.86
CsvHelperAsset5000046.946 ms2.6433711.0938.913.65 MB1.01
Sep______Asset1000000363.921 ms1.006671834.8363.9260.41 MB1.00
Sep_MT___Asset1000000104.427 ms0.296676394.0104.4261.51 MB1.00
Sylvan___Asset1000000541.503 ms1.496671233.1541.5260.57 MB1.00
ReadLine_Asset1000000422.719 ms1.166671579.6422.72385.07 MB9.16
CsvHelperAsset1000000938.489 ms2.58667711.5938.5260.58 MB1.00
Apple.M1.(Virtual) - PackageAssets with Quotes Benchmark Results (SERVER GC) (Sep 0.12.0.0, Sylvan 1.4.3.0, CsvHelper 33.1.0.26)
MethodScopeRowsMeanRatioMBMB/sns/rowAllocatedAlloc Ratio
Sep______Asset5000038.27 ms1.0233869.6765.513.48 MB1.00
Sep_MT___Asset5000024.23 ms0.65331373.3484.713.75 MB1.02
Sylvan___Asset5000078.94 ms2.1133421.61578.813.63 MB1.01
ReadLine_Asset5000073.58 ms1.9733452.31471.6119.44 MB8.86
CsvHelperAsset50000127.06 ms3.4033261.92541.313.64 MB1.01
Sep______Asset1000000896.49 ms1.00665742.7896.5260.41 MB1.00
Sep_MT___Asset1000000388.68 ms0.436651713.0388.7271.08 MB1.04
Sylvan___Asset10000001,703.56 ms1.90665390.81703.6260.57 MB1.00
ReadLine_Asset10000003,773.61 ms4.22665176.43773.62385.07 MB9.16
CsvHelperAsset10000002,813.28 ms3.14665236.72813.3260.58 MB1.00
Cobalt.100 - PackageAssets with Quotes Benchmark Results (SERVER GC) (Sep 0.12.0.0, Sylvan 1.4.3.0, CsvHelper 33.1.0.26)
MethodScopeRowsMeanRatioMBMB/sns/rowAllocatedAlloc Ratio
Sep______Asset5000038.23 ms1.0033873.2764.513.48 MB1.00
Sep_MT___Asset5000014.94 ms0.39332234.7298.713.54 MB1.00
Sylvan___Asset5000056.75 ms1.4833588.11135.113.63 MB1.01
ReadLine_Asset5000056.10 ms1.4733595.01122.0119.44 MB8.86
CsvHelperAsset50000105.98 ms2.7733314.92119.713.64 MB1.01
Sep______Asset1000000761.89 ms1.00667876.4761.9260.42 MB1.00
Sep_MT___Asset1000000244.95 ms0.326672725.9244.9262.42 MB1.01
Sylvan___Asset10000001,139.57 ms1.50667585.91139.6260.57 MB1.00
ReadLine_Asset10000001,236.30 ms1.62667540.11236.32385.07 MB9.16
CsvHelperAsset10000002,151.47 ms2.82667310.32151.5260.58 MB1.00
PackageAssets with Spaces and Quotes Benchmark Results

Similar to the benchmark related to quotes here spaces and quotes " are added to relevant columns to benchmark impact of trimming and unescape on low level column access. That is, basically " is prepended and appended to each column. This will test the assumed most common case and fast path part of trimming and unescaping in Sep. Sep is about 10x faster than CsvHelper for this. Sylvan does not appear to support automatic trimming and is, therefore, not included.

AMD.EPYC.7763 - PackageAssets with Spaces and Quotes Benchmark Results (Sep 0.12.0.0, Sylvan 1.4.3.0, CsvHelper 33.1.0.26)
MethodScopeRowsMeanRatioMBMB/sns/rowAllocatedAlloc Ratio
Sep_Cols5000012.98 ms1.00413211.7259.51.01 KB1.00
Sep_TrimCols5000019.39 ms1.49412148.8387.91.01 KB1.00
Sep_TrimUnescapeCols5000019.45 ms1.50412142.7389.01.01 KB1.00
Sep_TrimUnescapeTrimCols5000021.53 ms1.66411935.4430.71.01 KB1.00
CsvHelper_TrimUnescapeCols50000142.47 ms10.9841292.52849.5451.34 KB447.84
CsvHelper_TrimUnescapeTrimCols50000141.73 ms10.9241294.12834.5445.68 KB442.23
AMD.Ryzen.7.PRO.7840U.w.Radeon.780M - PackageAssets with Spaces and Quotes Benchmark Results (Sep 0.12.0.0, Sylvan 1.4.3.0, CsvHelper 33.1.0.26)
MethodScopeRowsMeanRatioMBMB/sns/rowAllocatedAlloc Ratio
Sep_Cols5000013.76 ms1.00413036.5275.11.01 KB1.00
Sep_TrimCols5000018.25 ms1.33412289.2364.91.01 KB1.00
Sep_TrimUnescapeCols5000018.43 ms1.34412266.6368.61.01 KB1.00
Sep_TrimUnescapeTrimCols5000021.16 ms1.54411974.2423.21.01 KB1.00
CsvHelper_TrimUnescapeCols50000127.73 ms9.2941327.02554.6451.34 KB447.84
CsvHelper_TrimUnescapeTrimCols50000126.60 ms9.2141329.92532.1445.68 KB442.22
AMD.Ryzen.9.5950X - PackageAssets with Spaces and Quotes Benchmark Results (Sep 0.9.0.0, Sylvan 1.3.9.0, CsvHelper 33.0.1.24)
MethodScopeRowsMeanRatioMBMB/sns/rowAllocatedAlloc Ratio
Sep_Cols500009.467 ms1.00414412.2189.31.05 KB1.00
Sep_TrimCols5000012.972 ms1.37413219.9259.41.06 KB1.01
Sep_TrimUnescapeCols5000013.630 ms1.44413064.5272.61.06 KB1.02
Sep_TrimUnescapeTrimCols5000015.502 ms1.64412694.4310.01.07 KB1.03
CsvHelper_TrimUnescapeCols5000098.444 ms10.4041424.31968.9451.52 KB431.70
CsvHelper_TrimUnescapeTrimCols5000097.110 ms10.2641430.11942.2445.86 KB426.29
AMD.Ryzen.9.9950X - PackageAssets with Spaces and Quotes Benchmark Results (Sep 0.12.0.0, Sylvan 1.4.3.0, CsvHelper 33.1.0.26)
MethodScopeRowsMeanRatioMBMB/sns/rowAllocatedAlloc Ratio
Sep_Cols500005.434 ms1.00417687.0108.71.01 KB1.00
Sep_TrimCols500007.906 ms1.46415283.2158.11.01 KB1.00
Sep_TrimUnescapeCols500008.541 ms1.57414890.5170.81.01 KB1.00
Sep_TrimUnescapeTrimCols500009.059 ms1.67414610.7181.21.01 KB1.00
CsvHelper_TrimUnescapeCols5000061.560 ms11.3341678.51231.2451.27 KB447.77
CsvHelper_TrimUnescapeTrimCols5000060.812 ms11.1941686.91216.2445.6 KB442.15
Apple.M1.(Virtual) - PackageAssets with Spaces and Quotes Benchmark Results (Sep 0.12.0.0, Sylvan 1.4.3.0, CsvHelper 33.1.0.26)
MethodScopeRowsMeanRatioMBMB/sns/rowAllocatedAlloc Ratio
Sep_Cols5000012.36 ms1.01413373.0247.1952 B1.00
Sep_TrimCols5000019.17 ms1.56412174.4383.3952 B1.00
Sep_TrimUnescapeCols5000020.35 ms1.66412047.8407.0952 B1.00
Sep_TrimUnescapeTrimCols5000017.07 ms1.39412441.6341.4952 B1.00
CsvHelper_TrimUnescapeCols50000110.49 ms8.9941377.22209.7462096 B485.39
CsvHelper_TrimUnescapeTrimCols50000130.51 ms10.6241319.32610.1456368 B479.38
Cobalt.100 - PackageAssets with Spaces and Quotes Benchmark Results (Sep 0.12.0.0, Sylvan 1.4.3.0, CsvHelper 33.1.0.26)
MethodScopeRowsMeanRatioMBMB/sns/rowAllocatedAlloc Ratio
Sep_Cols5000014.19 ms1.00412942.7283.9954 B1.00
Sep_TrimCols5000018.47 ms1.30412261.5369.4955 B1.00
Sep_TrimUnescapeCols5000019.41 ms1.37412152.0388.2955 B1.00
Sep_TrimUnescapeTrimCols5000020.91 ms1.47411997.4418.3952 B1.00
CsvHelper_TrimUnescapeCols50000120.00 ms8.4541348.12400.0462174 B484.46
CsvHelper_TrimUnescapeTrimCols50000115.80 ms8.1641360.72316.1459458 B481.61

Floats Reader Comparison Benchmarks

The FloatsReaderBench.cs benchmark demonstrates what Sep is built for. Namely parsing 32-bit floating points or features as in machine learning. Here a simple CSV-file is randomly generated with N ground truth values, N predicted result values and nothing else (note this was changed from version 0.3.0, prior to that there were some extra leading columns). N = 20 here. For example:

GT_Feature0;GT_Feature1;GT_Feature2;GT_Feature3;GT_Feature4;GT_Feature5;GT_Feature6;GT_Feature7;GT_Feature8;GT_Feature9;GT_Feature10;GT_Feature11;GT_Feature12;GT_Feature13;GT_Feature14;GT_Feature15;GT_Feature16;GT_Feature17;GT_Feature18;GT_Feature19;RE_Feature0;RE_Feature1;RE_Feature2;RE_Feature3;RE_Feature4;RE_Feature5;RE_Feature6;RE_Feature7;RE_Feature8;RE_Feature9;RE_Feature10;RE_Feature11;RE_Feature12;RE_Feature13;RE_Feature14;RE_Feature15;RE_Feature16;RE_Feature17;RE_Feature18;RE_Feature19 0.52276427;0.16843422;0.26259267;0.7244084;0.51292276;0.17365117;0.76125056;0.23458846;0.2573214;0.50560355;0.3202332;0.3809696;0.26024464;0.5174511;0.035318818;0.8141374;0.57719684;0.3974705;0.15219308;0.09011261;0.70515215;0.81618196;0.5399706;0.044147138;0.7111546;0.14776127;0.90621275;0.6925897;0.5164137;0.18637845;0.041509967;0.30819967;0.5831603;0.8210651;0.003954861;0.535722;0.8051845;0.7483589;0.3845737;0.14911908 0.6264564;0.11517637;0.24996082;0.77242833;0.2896067;0.6481459;0.14364648;0.044498358;0.6045593;0.51591337;0.050794687;0.42036617;0.7065823;0.6284636;0.21844554;0.013253775;0.36516154;0.2674384;0.06866083;0.71817476;0.07094294;0.46409357;0.012033525;0.7978093;0.43917948;0.5134962;0.4995968;0.008952909;0.82883793;0.012896823;0.0030740085;0.063773096;0.6541431;0.034539033;0.9135142;0.92897075;0.46119377;0.37533295;0.61660606;0.044443816 0.7922863;0.5323656;0.400699;0.29737252;0.9072584;0.58673894;0.73510516;0.019412167;0.88168067;0.9576787;0.33283427;0.7107;0.1623628;0.10314285;0.4521515;0.33324885;0.7761104;0.14854911;0.13469358;0.21566042;0.59166247;0.5128394;0.98702157;0.766223;0.67204326;0.7149494;0.2894748;0.55206;0.9898286;0.65083236;0.02421702;0.34540752;0.92906284;0.027142895;0.21974725;0.26544374;0.03848049;0.2161237;0.59233844;0.42221397 0.10609442;0.32130885;0.32383907;0.7511514;0.8258279;0.00904226;0.0420841;0.84049565;0.8958947;0.23807365;0.92621964;0.8452882;0.2794469;0.545344;0.63447595;0.62532926;0.19230893;0.29726416;0.18304513;0.029583583;0.23084833;0.93346167;0.98742676;0.78163713;0.13521992;0.8833956;0.18670778;0.29476836;0.5599867;0.5562107;0.7124796;0.121927656;0.5981778;0.39144602;0.88092715;0.4449142;0.34820423;0.96379805;0.46364686;0.54301775

For Scope=Floats the benchmark will parse the features as two spans of floats; one for ground truth values and one for predicted result values. Then calculates the mean squared error (MSE) of those as an example. For Sep this code is succinct and still incredibly efficient:

using var reader = Sep.Reader().From(Reader.CreateReader()); var groundTruthColNames = reader.Header.NamesStartingWith("GT_"); var resultColNames = groundTruthColNames.Select(n => n.Replace("GT_", "RE_", StringComparison.Ordinal)) .ToArray(); var sum = 0.0; var count = 0; foreach (var row in reader) { var gts = row[groundTruthColNames].Parse<float>(); var res = row[resultColNames].Parse<float>(); sum += MeanSquaredError(gts, res); ++count; } return sum / count;

Note how one can access and parse multiple columns easily while there are no repeated allocations for the parsed floating points. Sep internally handles a pool of arrays for handling multiple columns and returns spans for them.

The benchmark is based on an assumption of accessing columns by name per row. Ideally, one would look up the indices of the columns by name before enumerating rows, but this is a repeated nuisance to have to handle and Sep was built to avoid this. Hence, the comparison is based on looking up by name for each, even if this ends up adding a bit more code in the benchmark for other approaches.

As can be seen below, the actual low level parsing of the separated values is a tiny part of the total runtime for Sep for which the runtime is dominated by parsing the floating points. Since Sep uses csFastFloat for an integrated fast floating point parser, it is >2x faster than Sylvan for example. If using Sylvan one may consider using csFastFloat if that is an option. With the multi-threaded (MT) ParallelEnumerate implementation Sep is up to 23x faster than Sylvan.

CsvHelper suffers from the fact that one can only access the column as a string so this has to be allocated for each column (ReadLine by definition always allocates a string per column). Still CsvHelper is significantly slower than the naive ReadLine approach. With Sep being >4x faster than CsvHelper and up to 35x times faster when using ParallelEnumerate.

Note that ParallelEnumerate provides significant speedup over single-threaded parsing even though the source is only about 20 MB. This underlines how efficient ParallelEnumerate is, but bear in mind that this is for the case of repeated micro-benchmark runs.

It is a testament to how good the .NET and the .NET GC is that the ReadLine is pretty good compared to CsvHelper regardless of allocating a lot of strings.

AMD.EPYC.7763 - FloatsReader Benchmark Results (Sep 0.12.0.0, Sylvan 1.4.3.0, CsvHelper 33.1.0.26)
MethodScopeRowsMeanRatioMBMB/sns/rowAllocatedAlloc Ratio
Sep______Row250003.002 ms1.00206753.9120.11.24 KB1.00
Sylvan___Row250003.305 ms1.10206133.3132.210.7 KB8.61
ReadLine_Row2500018.502 ms6.16201095.7740.173489.62 KB59,161.45
CsvHelperRow2500037.670 ms12.5520538.11506.819.95 KB16.06
Sep______Cols250004.076 ms1.00204973.3163.01.24 KB1.00
Sylvan___Cols250005.792 ms1.42203500.2231.710.71 KB8.62
ReadLine_Cols2500018.372 ms4.51201103.4734.973489.62 KB59,161.45
CsvHelperCols2500040.450 ms9.9220501.21618.021340.16 KB17,179.50
Sep______Floats2500031.470 ms1.0020644.21258.87.89 KB1.00
Sep_MT___Floats2500012.902 ms0.41201571.2516.168.47 KB8.68
Sylvan___Floats2500082.451 ms2.6220245.93298.021.71 KB2.75
ReadLine_Floats25000110.689 ms3.5220183.14427.673492.96 KB9,313.96
CsvHelperFloats25000157.042 ms4.9920129.16281.722061.51 KB2,795.91
AMD.Ryzen.7.PRO.7840U.w.Radeon.780M - FloatsReader Benchmark Results (Sep 0.12.0.0, Sylvan 1.4.3.0, CsvHelper 33.1.0.26)
MethodScopeRowsMeanRatioMBMB/sns/rowAllocatedAlloc Ratio
Sep______Row250003.090 ms1.00206576.8123.61.24 KB1.00
Sylvan___Row250003.662 ms1.19205548.9146.510.7 KB8.61
ReadLine_Row2500014.759 ms4.78201376.7590.473489.62 KB59,161.45
CsvHelperRow2500040.346 ms13.0620503.61613.919.95 KB16.06
Sep______Cols250004.244 ms1.00204787.9169.81.24 KB1.00
Sylvan___Cols250006.501 ms1.53203125.5260.110.7 KB8.61
ReadLine_Cols2500015.460 ms3.64201314.3618.473489.62 KB59,161.45
CsvHelperCols2500042.710 ms10.0620475.81708.421340.16 KB17,179.50
Sep______Floats2500030.251 ms1.0020671.71210.17.89 KB1.00
Sep_MT___Floats250006.924 ms0.23202934.7277.0111.53 KB14.13
Sylvan___Floats2500078.705 ms2.6020258.23148.218.7 KB2.37
ReadLine_Floats25000102.918 ms3.4020197.44116.773492.94 KB9,313.96
CsvHelperFloats25000156.097 ms5.1620130.26243.922061.22 KB2,795.88
AMD.Ryzen.9.5950X - FloatsReader Benchmark Results (Sep 0.9.0.0, Sylvan 1.3.9.0, CsvHelper 33.0.1.24)
MethodScopeRowsMeanRatioMBMB/sns/rowAllocatedAlloc Ratio
Sep______Row250002.013 ms1.002010093.480.51.25 KB1.00
Sylvan___Row250002.355 ms1.17208627.494.210.7 KB8.56
ReadLine_Row250009.787 ms4.86202076.1391.573489.63 KB58,791.71
CsvHelperRow2500025.143 ms12.4920808.21005.720 KB16.00
Sep______Cols250002.666 ms1.00207622.2106.61.25 KB1.00
Sylvan___Cols250003.702 ms1.39205488.4148.110.71 KB8.54
ReadLine_Cols2500010.544 ms3.96201927.1421.873489.63 KB58,654.23
CsvHelperCols2500027.442 ms10.2920740.51097.721340.34 KB17,032.36
Sep______Floats2500020.297 ms1.00201001.1811.97.97 KB1.00
Sep_MT___Floats250003.780 ms0.19205375.6151.2179.49 KB22.51
Sylvan___Floats2500052.343 ms2.5820388.22093.718.88 KB2.37
ReadLine_Floats2500068.698 ms3.3820295.82747.973493.12 KB9,215.89
CsvHelperFloats25000100.913 ms4.9720201.44036.522061.69 KB2,766.49
AMD.Ryzen.9.9950X - FloatsReader Benchmark Results (Sep 0.12.0.0, Sylvan 1.4.3.0, CsvHelper 33.1.0.26)
MethodScopeRowsMeanRatioMBMB/sns/rowAllocatedAlloc Ratio
Sep______Row250001.265 ms1.002016063.250.61.24 KB1.00
Sylvan___Row250001.624 ms1.282012511.465.010.75 KB8.66
ReadLine_Row250006.545 ms5.17203104.8261.873489.62 KB59,161.45
CsvHelperRow2500014.820 ms11.72201371.1592.819.95 KB16.06
Sep______Cols250001.929 ms1.002010533.177.21.24 KB1.00
Sylvan___Cols250002.589 ms1.34207850.0103.510.7 KB8.61
ReadLine_Cols250006.814 ms3.53202982.2272.573489.62 KB59,161.45
CsvHelperCols2500015.995 ms8.29201270.4639.821340.17 KB17,179.50
Sep______Floats2500013.965 ms1.00201455.0558.67.89 KB1.00
Sep_MT___Floats250002.049 ms0.15209918.581.9178.98 KB22.68
Sylvan___Floats2500035.057 ms2.5120579.61402.318.67 KB2.37
ReadLine_Floats2500047.821 ms3.4220424.91912.873492.95 KB9,311.65
CsvHelperFloats2500066.495 ms4.7620305.62659.822061.22 KB2,795.19
Apple.M1.(Virtual) - FloatsReader Benchmark Results (Sep 0.12.0.0, Sylvan 1.4.3.0, CsvHelper 33.1.0.26)
MethodScopeRowsMeanRatioMBMB/sns/rowAllocatedAlloc Ratio
Sep______Row250003.546 ms1.00205716.9141.81.16 KB1.00
Sylvan___Row2500021.472 ms6.0820944.1858.910.36 KB8.90
ReadLine_Row2500019.918 ms5.64201017.8796.773489.62 KB63,132.02
CsvHelperRow2500037.422 ms10.5920541.71496.919.95 KB17.13
Sep______Cols250003.986 ms1.01205085.7159.41.16 KB1.00
Sylvan___Cols2500024.931 ms6.2920813.1997.210.52 KB9.04
ReadLine_Cols2500017.889 ms4.51201133.2715.673489.62 KB63,132.02
CsvHelperCols2500047.480 ms11.9820427.01899.221340.16 KB18,332.49
Sep______Floats2500034.253 ms1.0220591.81370.17.81 KB1.00
Sep_MT___Floats2500017.345 ms0.52201168.7693.8101.17 KB12.95
Sylvan___Floats2500087.013 ms2.6020233.03480.518.31 KB2.34
ReadLine_Floats25000101.080 ms3.0120200.64043.273492.94 KB9,407.10
CsvHelperFloats25000116.872 ms3.4920173.54674.922061.55 KB2,823.88
Cobalt.100 - FloatsReader Benchmark Results (Sep 0.12.0.0, Sylvan 1.4.3.0, CsvHelper 33.1.0.26)
MethodScopeRowsMeanRatioMBMB/sns/rowAllocatedAlloc Ratio
Sep______Row250003.295 ms1.00206166.2131.81.16 KB1.00
Sylvan___Row2500023.661 ms7.1820858.8946.410.32 KB8.86
ReadLine_Row2500016.952 ms5.14201198.6678.173489.62 KB63,132.02
CsvHelperRow2500033.251 ms10.0920611.11330.020.02 KB17.19
Sep______Cols250004.695 ms1.00204327.6187.81.16 KB1.00
Sylvan___Cols2500026.819 ms5.7120757.61072.810.32 KB8.87
ReadLine_Cols2500017.588 ms3.75201155.3703.573489.62 KB63,132.02
CsvHelperCols2500036.000 ms7.6720564.41440.021340.16 KB18,332.49
Sep______Floats2500029.130 ms1.0020697.61165.27.81 KB1.00
Sep_MT___Floats250008.689 ms0.30202338.6347.686.84 KB11.12
Sylvan___Floats2500086.914 ms2.9820233.83476.618.31 KB2.34
ReadLine_Floats2500094.119 ms3.2320215.93764.773492.94 KB9,407.10
CsvHelperFloats25000129.945 ms4.4620156.45197.822060.98 KB2,823.81

Writer Comparison Benchmarks

Writer benchmarks are still pending, but Sep is unlikely to be the fastest here since it is explicitly designed to make writing more convenient and flexible. Still efficient, but not necessarily fastest. That is, Sep does not require writing header up front and hence having to keep header column order and row values column order the same. This means Sep does not write columns directly upon definition but defers this until a new row has been fully defined and then is ended.

Example Catalogue

The following examples are available in ReadMeTest.cs.

Example - Write and Read Objects with Escape/Unescape

Person[] writePersons = [ new("Alice", new DateOnly(1990, 1, 1), "123 Main St, 1."), new("Bob", new DateOnly(1985, 5, 23), "456 Oak Ave"), new("Charlie", new DateOnly(2000, 12, 31), "789 Pine Rd, 3."), ]; // Write using var writer = Sep.New(',').Writer().Strict().ToText(); foreach (var person in writePersons) { using var row = writer.NewRow(); row[nameof(person.Name)].Set(person.Name); row[nameof(person.BirthDay)].Format(person.BirthDay); row[nameof(person.Address)].Set(person.Address); } var text = writer.ToString(); // Read using var reader = Sep.New(',').Reader().Strict().FromText(text); var readPersons = reader.Enumerate<Person>(row => new(Name: row[nameof(Person.Name)].ToString(), BirthDay: row[nameof(Person.BirthDay)].Parse<DateOnly>(), Address: row[nameof(Person.Address)].ToString())) .ToArray(); // Assert Assert.AreEqual(""" Name,BirthDay,Address Alice,01/01/1990,"123 Main St, 1." Bob,05/23/1985,456 Oak Ave Charlie,12/31/2000,"789 Pine Rd, 3." """, text); CollectionAssert.AreEqual(writePersons, readPersons);

with Person defined as:

record Person(string Name, DateOnly BirthDay, string Address);

Example - Copy Rows

var text = """ A;B;C;D;E;F Sep;🚀;1;1.2;0.1;0.5 CSV;;2;2.2;0.2;1.5 """; // Empty line at end is for line ending using var reader = Sep.Reader().FromText(text); using var writer = reader.Spec.Writer().ToText(); foreach (var readRow in reader) { using var writeRow = writer.NewRow(readRow); } Assert.AreEqual(text, writer.ToString());

Example - Copy Rows (Async)

var text = """ A;B;C;D;E;F Sep;🚀;1;1.2;0.1;0.5 CSV;;2;2.2;0.2;1.5 """; // Empty line at end is for line ending using var reader = await Sep.Reader().FromTextAsync(text); await using var writer = reader.Spec.Writer().ToText(); await foreach (var readRow in reader) { await using var writeRow = writer.NewRow(readRow); } Assert.AreEqual(text, writer.ToString());

Example - Skip Empty Rows

var text = """ A 1 2 3 4 """; // Empty line at end is for line ending var expected = new[] { 1, 2, 3, 4 }; // Disable col count check to allow empty rows using var reader = Sep.Reader(o => o with { DisableColCountCheck = true }).FromText(text); var actual = new List<int>(); foreach (var row in reader) { // Skip empty row if (row.Span.Length == 0) { continue; } actual.Add(row["A"].Parse<int>()); } CollectionAssert.AreEqual(expected, actual);

Example - Use Extension Method Enumerate within async/await Context (prior to C# 13.0)

Since SepReader.Row is a ref struct as covered above, one has to avoid referencing it directly in async context for C# prior to 13.0. This can be done in a number of ways, but one way is to use Enumerate extension method to parse/extract data from row like shown below.

var text = """ C 1 2 """; using var reader = Sep.Reader().FromText(text); var squaredSum = 0; // Use Enumerate to avoid referencing SepReader.Row in async context foreach (var value in reader.Enumerate(row => row["C"].Parse<int>())) { squaredSum += await Task.Run(() => value * value); } Assert.AreEqual(5, squaredSum);

Example - Use Local Function within async/await Context

Another way to avoid referencing SepReader.Row directly in async context is to use custom iterator via yield return to parse/extract data from row like shown below.

var text = """ C 1 2 """; using var reader = Sep.Reader().FromText(text); var squaredSum = 0; // Use custom local function Enumerate to avoid referencing // SepReader.Row in async context foreach (var value in Enumerate(reader)) { squaredSum += await Task.Run(() => value * value); } Assert.AreEqual(5, squaredSum); static IEnumerable<int> Enumerate(SepReader reader) { foreach (var r in reader) { yield return r["C"].Parse<int>(); } }

Example - Skip Lines/Rows Starting with Comment #

Below shows how one can skip lines starting with comment # since Sep does not have built-in support for this. Note that this presumes lines to be skipped before header do not contain quotes or rather line endings within quotes as that is not handled by the Peek() skipping. The rows starting with comment # after header are skipped if handling quoting is enabled in Sep options.

var text = """ # Comment 1 # Comment 2 A # Comment 3 1 2 # Comment 4 """; const char Comment = '#'; using var textReader = new StringReader(text); // Skip initial lines (not rows) before header while (textReader.Peek() == Comment && textReader.ReadLine() is string line) { } using var reader = Sep.Reader().From(textReader); var values = new List<int>(); foreach (var row in reader) { // Skip rows starting with comment if (row.Span.StartsWith([Comment])) { continue; } var value = row["A"].Parse<int>(); values.Add(value); } CollectionAssert.AreEqual(new int[] { 1, 2 }, values);

RFC-4180

While the RFC-4180 requires \r\n (CR,LF) as line ending, the well-known line endings (\r\n, \n and \r) are supported similar to .NET. Environment.NewLine is used when writing. Quoting is supported by simply matching pairs of quotes, no matter what.

Note that some libraries will claim conformance but the RFC is, perhaps naturally, quite strict e.g. only comma is supported as separator/delimiter. Sep defaults to using ; as separator if writing, while auto-detecting supported separators when reading. This is decidedly non-conforming.

The RFC defines the following condensed ABNF grammar:

file = [header CRLF] record *(CRLF record) [CRLF] header = name *(COMMA name) record = field *(COMMA field) name = field field = (escaped / non-escaped) escaped = DQUOTE *(TEXTDATA / COMMA / CR / LF / 2DQUOTE) DQUOTE non-escaped = *TEXTDATA COMMA = %x2C CR = %x0D ;as per section 6.1 of RFC 2234 [2] DQUOTE = %x22 ;as per section 6.1 of RFC 2234 [2] LF = %x0A ;as per section 6.1 of RFC 2234 [2] CRLF = CR LF ;as per section 6.1 of RFC 2234 [2] TEXTDATA = %x20-21 / %x23-2B / %x2D-7E

Note how TEXTDATA is restricted too, yet many will allow any character incl. emojis or similar (which Sep supports), but is not in conformance with the RFC.

Quotes inside an escaped field e.g. "fie""ld" are only allowed to be double quotes. Sep currently allows any pairs of quotes and quoting doesn't need to be at start of or end of field (col or column in Sep terminology).

All in all Sep takes a pretty pragmatic approach here as the primary use case is not exchanging data on the internet, but for use in machine learning pipelines or similar.

Frequently Asked Questions (FAQ)

Ask questions on GitHub and this section will be expanded. :)

  • Does Sep support object mapping like CsvHelper? No, Sep is a minimal library and does not support object mapping. First, this is usually supported via reflection, which Sep avoids. Second, object mapping often only works well in a few cases without actually writing custom mapping for each property, which then basically amounts to writing the parsing code yourself. If object mapping is a must have, consider writing your own source generator for it if you want to use Sep. Maybe some day Sep will have a built-in source generator, but not in the foreseeable future.

SepReader FAQ

SepWriter FAQ

Links

Public API Reference

[assembly: System.CLSCompliant(false)] [assembly: System.Reflection.AssemblyMetadata("IsTrimmable", "True")] [assembly: System.Reflection.AssemblyMetadata("RepositoryUrl", "https://github.com/nietras/Sep/")] [assembly: System.Resources.NeutralResourcesLanguage("en")] [assembly: System.Runtime.CompilerServices.InternalsVisibleTo("Sep.Benchmarks")] [assembly: System.Runtime.CompilerServices.InternalsVisibleTo("Sep.ComparisonBenchmarks")] [assembly: System.Runtime.CompilerServices.InternalsVisibleTo("Sep.Test")] [assembly: System.Runtime.CompilerServices.InternalsVisibleTo("Sep.XyzTest")] [assembly: System.Runtime.Versioning.TargetFramework(".NETCoreApp,Version=v9.0", FrameworkDisplayName=".NET 9.0")] namespace nietras.SeparatedValues { public readonly struct Sep : System.IEquatable<nietras.SeparatedValues.Sep> { public Sep() { } public Sep(char separator) { } public char Separator { get; init; } public static nietras.SeparatedValues.Sep? Auto { get; } public static nietras.SeparatedValues.Sep Default { get; } public static nietras.SeparatedValues.Sep New(char separator) { } public static nietras.SeparatedValues.SepReaderOptions Reader() { } public static nietras.SeparatedValues.SepReaderOptions Reader(System.Func<nietras.SeparatedValues.SepReaderOptions, nietras.SeparatedValues.SepReaderOptions> configure) { } public static nietras.SeparatedValues.SepWriterOptions Writer() { } public static nietras.SeparatedValues.SepWriterOptions Writer(System.Func<nietras.SeparatedValues.SepWriterOptions, nietras.SeparatedValues.SepWriterOptions> configure) { } } public enum SepColNotSetOption : byte { Throw = 0, Empty = 1, Skip = 2, } public delegate nietras.SeparatedValues.SepToString SepCreateToString(nietras.SeparatedValues.SepReaderHeader? maybeHeader, int colCount); public static class SepDefaults { public static System.StringComparer ColNameComparer { get; } public static System.Globalization.CultureInfo CultureInfo { get; } public static char Separator { get; } } [System.Diagnostics.DebuggerDisplay("{DebuggerDisplay,nq}")] public sealed class SepReader : nietras.SeparatedValues.SepReaderState, System.Collections.Generic.IAsyncEnumerable<nietras.SeparatedValues.SepReader.Row>, System.Collections.Generic.IEnumerable<nietras.SeparatedValues.SepReader.Row>, System.Collections.Generic.IEnumerator<nietras.SeparatedValues.SepReader.Row>, System.Collections.IEnumerable, System.Collections.IEnumerator, System.IDisposable { public nietras.SeparatedValues.SepReader.Row Current { get; } public bool HasHeader { get; } public bool HasRows { get; } public nietras.SeparatedValues.SepReaderHeader Header { get; } public bool IsEmpty { get; } public nietras.SeparatedValues.SepSpec Spec { get; } public nietras.SeparatedValues.SepReader.AsyncEnumerator GetAsyncEnumerator(System.Threading.CancellationToken cancellationToken = default) { } public nietras.SeparatedValues.SepReader GetEnumerator() { } public bool MoveNext() { } public System.Threading.Tasks.ValueTask<bool> MoveNextAsync(System.Threading.CancellationToken cancellationToken = default) { } public string ToString(int index) { } public readonly struct AsyncEnumerator : System.Collections.Generic.IAsyncEnumerator<nietras.SeparatedValues.SepReader.Row>, System.IAsyncDisposable { public nietras.SeparatedValues.SepReader.Row Current { get; } public System.Threading.Tasks.ValueTask DisposeAsync() { } public System.Threading.Tasks.ValueTask<bool> MoveNextAsync() { } } [System.Diagnostics.DebuggerDisplay("{DebuggerDisplay}")] public readonly ref struct Col { public System.ReadOnlySpan<char> Span { get; } public T Parse<T>() where T : System.ISpanParsable<T> { } public override string ToString() { } public T? TryParse<T>() where T : struct, System.ISpanParsable<T> { } public bool TryParse<T>(out T value) where T : System.ISpanParsable<T> { } } public readonly ref struct Cols { public int Count { get; } public nietras.SeparatedValues.SepReader.Col this[int index] { get; } public string CombinePathsToString() { } public System.ReadOnlySpan<char> Join(System.ReadOnlySpan<char> separator) { } public string JoinPathsToString() { } public string JoinToString(System.ReadOnlySpan<char> separator) { } public System.Span<T> Parse<T>() where T : System.ISpanParsable<T> { } public void Parse<T>(System.Span<T> span) where T : System.ISpanParsable<T> { } public T[] ParseToArray<T>() where T : System.ISpanParsable<T> { } public System.Span<T> Select<T>(method selector) { } public System.Span<T> Select<T>(nietras.SeparatedValues.SepReader.ColFunc<T> selector) { } public System.Span<string> ToStrings() { } public string[] ToStringsArray() { } public System.Span<T?> TryParse<T>() where T : struct, System.ISpanParsable<T> { } public void TryParse<T>(System.Span<T?> span) where T : struct, System.ISpanParsable<T> { } } [System.Diagnostics.DebuggerDisplay("{DebuggerDisplayPrefix,nq}{Span}")] [System.Diagnostics.DebuggerTypeProxy(typeof(nietras.SeparatedValues.SepReader.Row.DebugView))] public readonly ref struct Row { public int ColCount { get; } public nietras.SeparatedValues.SepReader.Col this[int index] { get; } public nietras.SeparatedValues.SepReader.Col this[System.Index index] { get; } public nietras.SeparatedValues.SepReader.Col this[string colName] { get; } public nietras.SeparatedValues.SepReader.Cols this[System.Range range] { get; } public nietras.SeparatedValues.SepReader.Cols this[System.ReadOnlySpan<int> indices] { get; } public nietras.SeparatedValues.SepReader.Cols this[System.Collections.Generic.IReadOnlyList<int> indices] { get; } public nietras.SeparatedValues.SepReader.Cols this[int[] indices] { get; } public nietras.SeparatedValues.SepReader.Cols this[System.ReadOnlySpan<string> colNames] { get; } public nietras.SeparatedValues.SepReader.Cols this[System.Collections.Generic.IReadOnlyList<string> colNames] { get; } public nietras.SeparatedValues.SepReader.Cols this[string[] colNames] { get; } public int LineNumberFrom { get; } public int LineNumberToExcl { get; } public int RowIndex { get; } public System.ReadOnlySpan<char> Span { get; } public System.Func<int, string> UnsafeToStringDelegate { get; } public override string ToString() { } public bool TryGet(string colName, out nietras.SeparatedValues.SepReader.Col col) { } } public delegate void ColAction(nietras.SeparatedValues.SepReader.Col col); public delegate T ColFunc<T>(nietras.SeparatedValues.SepReader.Col col); public delegate void ColsAction(nietras.SeparatedValues.SepReader.Cols col); public delegate void RowAction(nietras.SeparatedValues.SepReader.Row row); public delegate T RowFunc<T>(nietras.SeparatedValues.SepReader.Row row); public delegate bool RowTryFunc<T>(nietras.SeparatedValues.SepReader.Row row, out T value); } public static class SepReaderExtensions { public static System.Collections.Generic.IEnumerable<T> Enumerate<T>(this nietras.SeparatedValues.SepReader reader, nietras.SeparatedValues.SepReader.RowFunc<T> select) { } public static System.Collections.Generic.IEnumerable<T> Enumerate<T>(this nietras.SeparatedValues.SepReader reader, nietras.SeparatedValues.SepReader.RowTryFunc<T> trySelect) { } public static System.Collections.Generic.IAsyncEnumerable<T> EnumerateAsync<T>(this nietras.SeparatedValues.SepReader reader, nietras.SeparatedValues.SepReader.RowFunc<T> select) { } public static System.Collections.Generic.IAsyncEnumerable<T> EnumerateAsync<T>(this nietras.SeparatedValues.SepReader reader, nietras.SeparatedValues.SepReader.RowTryFunc<T> trySelect) { } public static nietras.SeparatedValues.SepReader From(this in nietras.SeparatedValues.SepReaderOptions options, System.IO.Stream stream) { } public static nietras.SeparatedValues.SepReader From(this in nietras.SeparatedValues.SepReaderOptions options, System.IO.TextReader reader) { } public static nietras.SeparatedValues.SepReader From(this in nietras.SeparatedValues.SepReaderOptions options, byte[] buffer) { } public static nietras.SeparatedValues.SepReader From(this in nietras.SeparatedValues.SepReaderOptions options, string name, System.Func<string, System.IO.Stream> nameToStream) { } public static nietras.SeparatedValues.SepReader From(this in nietras.SeparatedValues.SepReaderOptions options, string name, System.Func<string, System.IO.TextReader> nameToReader) { } public static System.Threading.Tasks.ValueTask<nietras.SeparatedValues.SepReader> FromAsync(this nietras.SeparatedValues.SepReaderOptions options, System.IO.Stream stream, System.Threading.CancellationToken cancellationToken = default) { } public static System.Threading.Tasks.ValueTask<nietras.SeparatedValues.SepReader> FromAsync(this nietras.SeparatedValues.SepReaderOptions options, System.IO.TextReader reader, System.Threading.CancellationToken cancellationToken = default) { } public static System.Threading.Tasks.ValueTask<nietras.SeparatedValues.SepReader> FromAsync(this nietras.SeparatedValues.SepReaderOptions options, byte[] buffer, System.Threading.CancellationToken cancellationToken = default) { } public static System.Threading.Tasks.ValueTask<nietras.SeparatedValues.SepReader> FromAsync(this nietras.SeparatedValues.SepReaderOptions options, string name, System.Func<string, System.IO.Stream> nameToStream, System.Threading.CancellationToken cancellationToken = default) { } public static System.Threading.Tasks.ValueTask<nietras.SeparatedValues.SepReader> FromAsync(this nietras.SeparatedValues.SepReaderOptions options, string name, System.Func<string, System.IO.TextReader> nameToReader, System.Threading.CancellationToken cancellationToken = default) { } public static nietras.SeparatedValues.SepReader FromFile(this in nietras.SeparatedValues.SepReaderOptions options, string filePath) { } public static System.Threading.Tasks.ValueTask<nietras.SeparatedValues.SepReader> FromFileAsync(this nietras.SeparatedValues.SepReaderOptions options, string filePath, System.Threading.CancellationToken cancellationToken = default) { } public static nietras.SeparatedValues.SepReader FromText(this in nietras.SeparatedValues.SepReaderOptions options, string text) { } public static System.Threading.Tasks.ValueTask<nietras.SeparatedValues.SepReader> FromTextAsync(this nietras.SeparatedValues.SepReaderOptions options, string text, System.Threading.CancellationToken cancellationToken = default) { } public static System.Collections.Generic.IEnumerable<T> ParallelEnumerate<T>(this nietras.SeparatedValues.SepReader reader, nietras.SeparatedValues.SepReader.RowFunc<T> select) { } public static System.Collections.Generic.IEnumerable<T> ParallelEnumerate<T>(this nietras.SeparatedValues.SepReader reader, nietras.SeparatedValues.SepReader.RowTryFunc<T> trySelect) { } public static System.Collections.Generic.IEnumerable<T> ParallelEnumerate<T>(this nietras.SeparatedValues.SepReader reader, nietras.SeparatedValues.SepReader.RowFunc<T> select, int degreeOfParallism) { } public static System.Collections.Generic.IEnumerable<T> ParallelEnumerate<T>(this nietras.SeparatedValues.SepReader reader, nietras.SeparatedValues.SepReader.RowTryFunc<T> trySelect, int degreeOfParallism) { } public static nietras.SeparatedValues.SepReaderOptions Reader(this nietras.SeparatedValues.Sep sep) { } public static nietras.SeparatedValues.SepReaderOptions Reader(this nietras.SeparatedValues.Sep? sep) { } public static nietras.SeparatedValues.SepReaderOptions Reader(this nietras.SeparatedValues.SepSpec spec) { } public static nietras.SeparatedValues.SepReaderOptions Reader(this nietras.SeparatedValues.Sep sep, System.Func<nietras.SeparatedValues.SepReaderOptions, nietras.SeparatedValues.SepReaderOptions> configure) { } public static nietras.SeparatedValues.SepReaderOptions Reader(this nietras.SeparatedValues.Sep? sep, System.Func<nietras.SeparatedValues.SepReaderOptions, nietras.SeparatedValues.SepReaderOptions> configure) { } public static nietras.SeparatedValues.SepReaderOptions Reader(this nietras.SeparatedValues.SepSpec spec, System.Func<nietras.SeparatedValues.SepReaderOptions, nietras.SeparatedValues.SepReaderOptions> configure) { } public static nietras.SeparatedValues.SepReaderOptions Strict(this in nietras.SeparatedValues.SepReaderOptions options) { } } public sealed class SepReaderHeader { public System.Collections.Generic.IReadOnlyList<string> ColNames { get; } public bool IsEmpty { get; } public static nietras.SeparatedValues.SepReaderHeader Empty { get; } public int IndexOf(System.ReadOnlySpan<char> colName) { } public int IndexOf(string colName) { } public int[] IndicesOf(System.Collections.Generic.IReadOnlyList<string> colNames) { } public int[] IndicesOf([System.Runtime.CompilerServices.ParamCollection] [System.Runtime.CompilerServices.ScopedRef] System.ReadOnlySpan<string> colNames) { } public int[] IndicesOf(params string[] colNames) { } public void IndicesOf(System.ReadOnlySpan<string> colNames, System.Span<int> colIndices) { } public System.Collections.Generic.IReadOnlyList<string> NamesStartingWith(string prefix, System.StringComparison comparison = 4) { } public override string ToString() { } public bool TryIndexOf(System.ReadOnlySpan<char> colName, out int colIndex) { } public bool TryIndexOf(string colName, out int colIndex) { } } public readonly struct SepReaderOptions : System.IEquatable<nietras.SeparatedValues.SepReaderOptions> { public SepReaderOptions() { } public SepReaderOptions(nietras.SeparatedValues.Sep? sep) { } public bool AsyncContinueOnCapturedContext { get; init; } public System.Collections.Generic.IEqualityComparer<string> ColNameComparer { get; init; } public nietras.SeparatedValues.SepCreateToString CreateToString { get; init; } public System.Globalization.CultureInfo? CultureInfo { get; init; } public bool DisableColCountCheck { get; init; } public bool DisableFastFloat { get; init; } public bool DisableQuotesParsing { get; init; } public bool HasHeader { get; init; } public int InitialBufferLength { get; init; } public nietras.SeparatedValues.Sep? Sep { get; init; } public nietras.SeparatedValues.SepTrim Trim { get; init; } public bool Unescape { get; init; } } public class SepReaderState : System.IDisposable { public void Dispose() { } } public static class SepReaderWriterExtensions { public static void CopyTo(this nietras.SeparatedValues.SepReader.Row readerRow, nietras.SeparatedValues.SepWriter.Row writerRow) { } public static nietras.SeparatedValues.SepWriter.Row NewRow(this nietras.SeparatedValues.SepWriter writer, nietras.SeparatedValues.SepReader.Row rowToCopy) { } public static nietras.SeparatedValues.SepWriter.Row NewRow(this nietras.SeparatedValues.SepWriter writer, nietras.SeparatedValues.SepReader.Row rowToCopy, System.Threading.CancellationToken cancellationToken) { } } public readonly struct SepSpec : System.IEquatable<nietras.SeparatedValues.SepSpec> { public SepSpec() { } public SepSpec(nietras.SeparatedValues.Sep sep, System.Globalization.CultureInfo? cultureInfo) { } public SepSpec(nietras.SeparatedValues.Sep sep, System.Globalization.CultureInfo? cultureInfo, bool asyncContinueOnCapturedContext) { } public bool AsyncContinueOnCapturedContext { get; init; } public System.Globalization.CultureInfo? CultureInfo { get; init; } public nietras.SeparatedValues.Sep Sep { get; init; } } public abstract class SepToString : System.IDisposable { protected SepToString() { } public virtual bool IsThreadSafe { get; } public static nietras.SeparatedValues.SepCreateToString Direct { get; } public void Dispose() { } protected virtual void Dispose(bool disposing) { } public abstract string ToString(System.ReadOnlySpan<char> colSpan, int colIndex); public static nietras.SeparatedValues.SepCreateToString OnePool(int maximumStringLength = 32, int initialCapacity = 64, int maximumCapacity = 4096) { } public static nietras.SeparatedValues.SepCreateToString PoolPerCol(int maximumStringLength = 32, int initialCapacity = 64, int maximumCapacity = 4096) { } public static nietras.SeparatedValues.SepCreateToString PoolPerColThreadSafe(int maximumStringLength = 32, int initialCapacity = 64, int maximumCapacity = 4096) { } public static nietras.SeparatedValues.SepCreateToString PoolPerColThreadSafeFixedCapacity(int maximumStringLength = 32, int capacity = 2048) { } } [System.Flags] public enum SepTrim : byte { None = 0, Outer = 1, AfterUnescape = 2, All = 3, } [System.Diagnostics.DebuggerDisplay("{DebuggerDisplay,nq}")] public sealed class SepWriter : System.IAsyncDisposable, System.IDisposable { public nietras.SeparatedValues.SepWriterHeader Header { get; } public nietras.SeparatedValues.SepSpec Spec { get; } public void Dispose() { } public System.Threading.Tasks.ValueTask DisposeAsync() { } public void Flush() { } public System.Threading.Tasks.Task FlushAsync(System.Threading.CancellationToken cancellationToken = default) { } public nietras.SeparatedValues.SepWriter.Row NewRow() { } public nietras.SeparatedValues.SepWriter.Row NewRow(System.Threading.CancellationToken cancellationToken) { } public override string ToString() { } public readonly ref struct Col { public void Format<T>(T value) where T : System.ISpanFormattable { } public void Format<T>(T value, System.ReadOnlySpan<char> format) where T : System.ISpanFormattable { } public void Set(System.ReadOnlySpan<byte> utf8Span) { } public void Set(System.ReadOnlySpan<char> span) { } public void Set([System.Runtime.CompilerServices.InterpolatedStringHandlerArgument("")] ref nietras.SeparatedValues.SepWriter.Col.FormatInterpolatedStringHandler handler) { } public void Set(System.IFormatProvider? provider, [System.Runtime.CompilerServices.InterpolatedStringHandlerArgument(new string?[]?[] { "", "provider"})] ref nietras.SeparatedValues.SepWriter.Col.FormatInterpolatedStringHandler handler) { } [System.Runtime.CompilerServices.InterpolatedStringHandler] public ref struct FormatInterpolatedStringHandler { public FormatInterpolatedStringHandler(int literalLength, int formattedCount, nietras.SeparatedValues.SepWriter.Col col) { } public FormatInterpolatedStringHandler(int literalLength, int formattedCount, nietras.SeparatedValues.SepWriter.Col col, System.IFormatProvider? provider) { } public void AppendFormatted(System.ReadOnlySpan<char> value) { } public void AppendFormatted(string? value) { } public void AppendFormatted(System.ReadOnlySpan<char> value, int alignment = 0, string? format = null) { } public void AppendFormatted(object? value, int alignment = 0, string? format = null) { } public void AppendFormatted(string? value, int alignment = 0, string? format = null) { } public void AppendFormatted<T>(T value) { } public void AppendFormatted<T>(T value, int alignment) { } public void AppendFormatted<T>(T value, string? format) { } public void AppendFormatted<T>(T value, int alignment, string? format) { } public void AppendLiteral(string value) { } } } public readonly ref struct Cols { public int Count { get; } public nietras.SeparatedValues.SepWriter.Col this[int colIndex] { get; } public void Format<T>(System.Collections.Generic.IReadOnlyList<T> values) where T : System.ISpanFormattable { } public void Format<T>([System.Runtime.CompilerServices.ParamCollection] [System.Runtime.CompilerServices.ScopedRef] System.ReadOnlySpan<T> values) where T : System.ISpanFormattable { } public void Format<T>(System.Span<T> values) where T : System.ISpanFormattable { } public void Format<T>(T[] values) where T : System.ISpanFormattable { } public void Format<T>(System.ReadOnlySpan<T> values, nietras.SeparatedValues.SepWriter.ColAction<T> format) { } public void Set(System.Collections.Generic.IReadOnlyList<string> values) { } public void Set([System.Runtime.CompilerServices.ParamCollection] [System.Runtime.CompilerServices.ScopedRef] System.ReadOnlySpan<string> values) { } public void Set(nietras.SeparatedValues.SepReader.Cols cols) { } public void Set(string[] values) { } } public ref struct Row : System.IAsyncDisposable, System.IDisposable { public nietras.SeparatedValues.SepWriter.Col this[int colIndex] { get; } public nietras.SeparatedValues.SepWriter.Col this[string colName] { get; } public nietras.SeparatedValues.SepWriter.Cols this[System.ReadOnlySpan<int> indices] { get; } public nietras.SeparatedValues.SepWriter.Cols this[System.ReadOnlySpan<string> colNames] { get; } public nietras.SeparatedValues.SepWriter.Cols this[System.Collections.Generic.IReadOnlyList<string> colNames] { get; } public nietras.SeparatedValues.SepWriter.Cols this[string[] colNames] { get; } public void Dispose() { } public System.Threading.Tasks.ValueTask DisposeAsync() { } } public delegate void ColAction(nietras.SeparatedValues.SepWriter.Col col); public delegate void ColAction<T>(nietras.SeparatedValues.SepWriter.Col col, T value); public delegate void RowAction(nietras.SeparatedValues.SepWriter.Row row); } public static class SepWriterExtensions { public static nietras.SeparatedValues.SepWriterOptions Strict(this in nietras.SeparatedValues.SepWriterOptions options) { } public static nietras.SeparatedValues.SepWriter To(this in nietras.SeparatedValues.SepWriterOptions options, System.IO.Stream stream) { } public static nietras.SeparatedValues.SepWriter To(this in nietras.SeparatedValues.SepWriterOptions options, System.IO.TextWriter writer) { } public static nietras.SeparatedValues.SepWriter To(this in nietras.SeparatedValues.SepWriterOptions options, System.Text.StringBuilder stringBuilder) { } public static nietras.SeparatedValues.SepWriter To(this in nietras.SeparatedValues.SepWriterOptions options, System.IO.Stream stream, bool leaveOpen) { } public static nietras.SeparatedValues.SepWriter To(this in nietras.SeparatedValues.SepWriterOptions options, System.IO.TextWriter writer, bool leaveOpen) { } public static nietras.SeparatedValues.SepWriter To(this in nietras.SeparatedValues.SepWriterOptions options, string name, System.Func<string, System.IO.Stream> nameToStream, bool leaveOpen = false) { } public static nietras.SeparatedValues.SepWriter To(this in nietras.SeparatedValues.SepWriterOptions options, string name, System.Func<string, System.IO.TextWriter> nameToWriter, bool leaveOpen = false) { } public static nietras.SeparatedValues.SepWriter ToFile(this in nietras.SeparatedValues.SepWriterOptions options, string filePath) { } public static nietras.SeparatedValues.SepWriter ToText(this in nietras.SeparatedValues.SepWriterOptions options) { } public static nietras.SeparatedValues.SepWriter ToText(this in nietras.SeparatedValues.SepWriterOptions options, int capacity) { } public static nietras.SeparatedValues.SepWriterOptions Writer(this nietras.SeparatedValues.Sep sep) { } public static nietras.SeparatedValues.SepWriterOptions Writer(this nietras.SeparatedValues.SepSpec spec) { } public static nietras.SeparatedValues.SepWriterOptions Writer(this nietras.SeparatedValues.Sep sep, System.Func<nietras.SeparatedValues.SepWriterOptions, nietras.SeparatedValues.SepWriterOptions> configure) { } public static nietras.SeparatedValues.SepWriterOptions Writer(this nietras.SeparatedValues.SepSpec spec, System.Func<nietras.SeparatedValues.SepWriterOptions, nietras.SeparatedValues.SepWriterOptions> configure) { } } [System.Diagnostics.DebuggerDisplay("{DebuggerDisplay,nq}")] [System.Diagnostics.DebuggerTypeProxy(typeof(nietras.SeparatedValues.SepWriterHeader.DebugView))] public sealed class SepWriterHeader { public void Add(System.Collections.Generic.IReadOnlyList<string> colNames) { } public void Add([System.Runtime.CompilerServices.ParamCollection] [System.Runtime.CompilerServices.ScopedRef] System.ReadOnlySpan<string> colNames) { } public void Add(string colName) { } public void Add(string[] colNames) { } public bool Contains(string colName) { } public bool TryAdd(string colName) { } public void Write() { } public System.Threading.Tasks.ValueTask WriteAsync(System.Threading.CancellationToken cancellationToken = default) { } } public readonly struct SepWriterOptions : System.IEquatable<nietras.SeparatedValues.SepWriterOptions> { public SepWriterOptions() { } public SepWriterOptions(nietras.SeparatedValues.Sep sep) { } public bool AsyncContinueOnCapturedContext { get; init; } public nietras.SeparatedValues.SepColNotSetOption ColNotSetOption { get; init; } public System.Globalization.CultureInfo? CultureInfo { get; init; } public bool DisableColCountCheck { get; init; } public bool Escape { get; init; } public nietras.SeparatedValues.Sep Sep { get; init; } public bool WriteHeader { get; init; } } }

关于 About

World's Fastest .NET CSV Parser. Modern, minimal, fast, zero allocation, reading and writing of separated values (`csv`, `tsv` etc.). Cross-platform, trimmable and AOT/NativeAOT compatible.
csharpcsvcsv-parsercsv-readercsv-writerdotnetperformancesimd

语言 Languages

C#99.6%
PowerShell0.4%

提交活跃度 Commit Activity

代码提交热力图
过去 52 周的开发活跃度
134
Total Commits
峰值: 19次/周
Less
More

核心贡献者 Contributors