You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/core/extensions/primitives.md
+5-5Lines changed: 5 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -3,12 +3,12 @@ title: "Primitives: the extensions library for .NET"
3
3
description: Learn about the various primitive types from the Microsoft.Extensions.Primitives library.
4
4
author: IEvangelist
5
5
ms.author: dapine
6
-
ms.date: 10/21/2021
6
+
ms.date: 10/22/2021
7
7
---
8
8
9
9
# Primitives: The extensions library for .NET
10
10
11
-
In this article, you'll learn about the [Microsoft.Extensions.Primitives](/dotnet/api/microsoft.extensions.primitives) library. The primitives in this article are *not* to be confused with .NET primitive types from the BCL, or that of the C# language. Instead, the types within the primitives library serve as building blocks for some of the peripheral .NET NuGet packages such as:
11
+
In this article, you'll learn about the [Microsoft.Extensions.Primitives](/dotnet/api/microsoft.extensions.primitives) library. The primitives in this article are *not* to be confused with .NET primitive types from the BCL, or that of the C# language. Instead, the types within the primitives library serve as building blocks for some of the peripheral .NET NuGet packages, such as:
@@ -72,11 +72,11 @@ The `StringSegment` struct provides [many methods](/dotnet/api/microsoft.extensi
72
72
73
73
### The `StringTokenizer` type
74
74
75
-
The <xref:Microsoft.Extensions.Primitives.StringTokenizer> object is a struct type that tokenizes a `string` into `StringSegment` instances. The tokenization of large strings usually involves splitting the string apart and iterating over it. With that said, <xref:System.String.Split%2A?displayProperty=nameWithType> probably comes to mind. Their APIs are similar, but in general, <xref:Microsoft.Extensions.Primitives.StringTokenizer> provides better performance. First, consider the following example:
75
+
The <xref:Microsoft.Extensions.Primitives.StringTokenizer> object is a struct type that tokenizes a `string` into `StringSegment` instances. The tokenization of large strings usually involves splitting the string apart and iterating over it. With that said, <xref:System.String.Split%2A?displayProperty=nameWithType> probably comes to mind. These APIs are similar, but in general, <xref:Microsoft.Extensions.Primitives.StringTokenizer> provides better performance. First, consider the following example:
In the preceding code, an instance of the `StringTokenizer` type is created given 900 auto-generated paragraphs of :::no-loc text="Lorem Ipsum"::: text and an array with a single value of whitespace`' '`. Each value within the tokenizer is represented as a `StringSegment`. The code iterates the segments, allowing the consumer to interact with each `segment`.
79
+
In the preceding code, an instance of the `StringTokenizer` type is created given 900 auto-generated paragraphs of :::no-loc text="Lorem Ipsum"::: text and an array with a single value of a white-space character`' '`. Each value within the tokenizer is represented as a `StringSegment`. The code iterates the segments, allowing the consumer to interact with each `segment`.
80
80
81
81
#### Benchmark comparing `StringTokenizer` to `string.Split`
82
82
@@ -90,7 +90,7 @@ With the various ways of slicing and dicing strings, it feels appropriate to com
Both methods are very similar looking on the API surface area, and they're both capable of splitting a large string into chunks. The benchmark results below show that the `StringTokenizer` approach is nearly three times faster, but *results may vary*. As with all performance considerations, you should evaluate your specific use case.
93
+
Both methods look similar on the API surface area, and they're both capable of splitting a large string into chunks. The benchmark results below show that the `StringTokenizer` approach is nearly three times faster, but *results may vary*. As with all performance considerations, you should evaluate your specific use case.
94
94
95
95
| Method | Mean | Error | Standard deviation | Median | Ratio | Ratio standard deviation |
0 commit comments