Skip to content

Commit 8f90557

Browse files
authored
Suggestions from peer review (dotnet#26621)
1 parent 0d9f238 commit 8f90557

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

docs/core/extensions/primitives.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@ title: "Primitives: the extensions library for .NET"
33
description: Learn about the various primitive types from the Microsoft.Extensions.Primitives library.
44
author: IEvangelist
55
ms.author: dapine
6-
ms.date: 10/21/2021
6+
ms.date: 10/22/2021
77
---
88

99
# Primitives: The extensions library for .NET
1010

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:
1212

1313
- [`Microsoft.Extensions.Configuration`](https://www.nuget.org/packages/Microsoft.Extensions.Configuration)
1414
- [`Microsoft.Extensions.Configuration.FileExtensions`](https://www.nuget.org/packages/Microsoft.Extensions.Configuration.FileExtensions)
@@ -72,11 +72,11 @@ The `StringSegment` struct provides [many methods](/dotnet/api/microsoft.extensi
7272

7373
### The `StringTokenizer` type
7474

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:
7676

7777
:::code source="./snippets/primitives/string/Example.Tokenizer.cs" id="Tokenizer":::
7878

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 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`.
8080

8181
#### Benchmark comparing `StringTokenizer` to `string.Split`
8282

@@ -90,7 +90,7 @@ With the various ways of slicing and dicing strings, it feels appropriate to com
9090

9191
:::code source="./snippets/primitives/string/Example.Tokenizer.cs" id="SplitBenchmark":::
9292

93-
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.
9494

9595
| Method | Mean | Error | Standard deviation | Median | Ratio | Ratio standard deviation |
9696
|-------------|----------:|----------:|-------------------:|----------:|------:|-------------------------:|

0 commit comments

Comments
 (0)