Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a fast pass for ZString.Join when the argument is a string #94

Merged
merged 2 commits into from
Sep 21, 2023

Conversation

hadashiA
Copy link
Contributor

Add fast pass when the argument of ZString.Join is a string, similar to string.Join.

Benchmark result

    public class JoinBenchmark
    {
        string[] Source = new[] { "111", "222", "333" };

        [Benchmark]
        public string StringJoin()
        {
            return string.Join(",", Source);
        }

        [Benchmark]
        public string ZStringJoin() 
        {
            return ZString.Join(",", Source);
        }
    }

Before

|      Method |     Mean |    Error |   StdDev |
|------------ |---------:|---------:|---------:|
|  StringJoin | 25.43 ns | 0.458 ns | 0.406 ns |
| ZStringJoin | 56.79 ns | 0.600 ns | 0.531 ns |

After

|      Method |     Mean |    Error |   StdDev | Ratio |
|------------ |---------:|---------:|---------:|------:|
|  StringJoin | 26.37 ns | 0.203 ns | 0.190 ns |  1.00 |
| ZStringJoin | 28.57 ns | 0.195 ns | 0.182 ns |  1.08 |

@hadashiA hadashiA marked this pull request as ready for review September 21, 2023 06:45
@hadashiA hadashiA merged commit 1639a8f into master Sep 21, 2023
2 checks passed
@hadashiA hadashiA deleted the hadashiA/join branch September 21, 2023 08:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant