Skip to content

Commit

Permalink
Updated documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
linkdotnet committed Apr 11, 2022
1 parent 54f2a91 commit 686ae91
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ All notable changes to **ValueStringBuilder** will be documented in this file. T

### Added

- `LastIndexOf` to find the last occurence in the represented string
- `LastIndexOf` to find the last occurence in the represented string.
- `Replace<T>` added for generic replacement in the string builder.

## [0.9.5] - 2022-04-10

Expand Down
15 changes: 9 additions & 6 deletions docs/site/articles/comparison.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,24 @@ The `StringBuilder` shipped with the .NET Framework itself is a all-purpose stri
- `StringBuilder` works not on `Span<T>` but more on `string`s or `char`s. Sometimes even with pointers
- `StringBuilder` uses chunks to represent the string, which the larger the string gets, the better it can perform. `ValueStringBuilder` only has one internal `Span` as representation which can cause fragmentation on very big strings.
- `StringBuilder` has a richer API as the `ValueStringBuilder`. In the future they should have the same amount of API's as the `StringBuilder` is the "big brother" of this package.
- `ValueStringBuilder` has different API calls like [`IndexOf`](xref:LinkDotNet.StringBuilder.ValueStringBuilder.IndexOf(ReadOnlySpan{System.Char})) or [`LastIndexOf`](xref:LinkDotNet.StringBuilder.ValueStringBuilder.LastIndexOf(ReadOnlySpan{System.Char})).

## `ZString`
Both string builder use similiar concepts to achieve. Both,`ValueStringBuilder` and `ZString`, are declared as `struct`s. `ValueStringBuilder` goes one step further and enforces its lifecycle to live on the **stack** and can never be put on the **heap**.

**Key differences**:
* `ValueStringBuilder` is a `ref struct` which can never placed on the heap. `ZString` can be defined as a `class` field.
* `ZString` has a very big initial buffer in its default (64kb) which can lead to more pressure on the GC.
* `ZString` is more general purpose than `ValueStringBuilder` is.
* `ZString` offers a richer API than the `ValueStringBuilder`. In the future that should change.
- `ValueStringBuilder` is a `ref struct` which can never placed on the heap. `ZString` can be defined as a `class` field.
- `ZString` has a very big initial buffer in its default (64kb) which can lead to more pressure on the GC.
- `ZString` is more general purpose than `ValueStringBuilder` is.
- `ZString` offers a richer API than the `ValueStringBuilder`. In the future that should change.
- `ValueStringBuilder` has different API calls like [`IndexOf`](xref:LinkDotNet.StringBuilder.ValueStringBuilder.IndexOf(ReadOnlySpan{System.Char})) or [`LastIndexOf`](xref:LinkDotNet.StringBuilder.ValueStringBuilder.LastIndexOf(ReadOnlySpan{System.Char})).


## Benchmark

The following table gives you a small comparison between the `StringBuilder` which is part of .NET, [`ZString`](https://github.com/Cysharp/ZString) and the `ValueStringBuilder`:

```no-class
```
| Method | Mean | Error | StdDev | Median | Ratio | RatioSD | Gen 0 | Gen 1 | Allocated |
|-------------------- |-----------:|---------:|----------:|-----------:|------:|--------:|--------:|-------:|----------:|
| DotNetStringBuilder | 401.7 ns | 29.15 ns | 84.56 ns | 373.4 ns | 1.00 | 0.00 | 0.3576 | - | 1,496 B |
Expand All @@ -43,7 +45,8 @@ For more comparison check the documentation.

Another benchmark shows that this `ValueStringBuilder` uses less memory when it comes to appending `ValueTypes` such as `int`, `double`, ...

```no-class

```
| Method | Mean | Error | StdDev | Gen 0 | Gen 1 | Allocated |
|-------------------- |---------:|---------:|---------:|--------:|-------:|----------:|
| DotNetStringBuilder | 16.31 us | 0.414 us | 1.208 us | 1.5259 | - | 6 KB |
Expand Down

0 comments on commit 686ae91

Please sign in to comment.