Git Product home page Git Product logo

Comments (4)

udaken avatar udaken commented on July 23, 2024

solution.

In a generic method, branch when T is a string.

Change the sb.Append(values[i]); to the following.

if (typeof(T) == typeof(string))
{
    sb.Append(Unsafe.As<string>(values[i]));
}
else
{
    sb.Append(values[i]);
}

The benchmark results are detailed below.

Method Mean Error Gen 0 Gen 1 Gen 2 Allocated
JoinEmptyList 21.415 ns NA 0.0048 - - 40 B
ZJoinEmptyList 15.892 ns NA - - - -
JoinList1 27.790 ns NA 0.0048 - - 40 B
ZJoinList1 34.238 ns NA 0.0114 - - 96 B
JoinArray1 3.721 ns NA - - - -
ZJoinArray1 39.208 ns NA 0.0114 - - 96 B
JoinEnumerable1 23.032 ns NA 0.0048 - - 40 B
ZJoinEnumerable1 54.425 ns NA 0.0162 - - 136 B
JoinList2 91.815 ns NA 0.0248 - - 208 B
ZJoinList2 54.395 ns NA 0.0200 - - 168 B
JoinArray2 26.446 ns NA 0.0201 - - 168 B
ZJoinArray2 63.063 ns NA 0.0200 - - 168 B
JoinEnumerable2 75.099 ns NA 0.0248 - - 208 B
ZJoinEnumerable2 76.057 ns NA 0.0248 - - 208 B
JoinList10 514.121 ns NA 0.2842 0.0019 - 2384 B
ZJoinList10 177.401 ns NA 0.0908 0.0002 - 760 B
JoinArray10 106.759 ns NA 0.0908 0.0002 - 760 B
ZJoinArray10 202.832 ns NA 0.0908 0.0002 - 760 B
JoinEnumerable10 413.451 ns NA 0.2847 0.0024 - 2384 B
ZJoinEnumerable10 218.206 ns NA 0.0956 0.0002 - 800 B

from zstring.

udaken avatar udaken commented on July 23, 2024

I edited the first comment to change the amount of data and add an array case.

System.Join seems to be optimized for arrays.

from zstring.

udaken avatar udaken commented on July 23, 2024

In #18, it was always faster than in version 2.1.2 when using string as a type argument.

However, String.Join is faster in some cases.

Ratio(ZString Ver 2.1.2, base is CLR) Ratio(udaken/ZString@6b94c72, base is CLR))
Join(string, List<string>) with empty List 56.36% 23.08%
Join(string, List<string>) with 1 element 174.39% ⚠ 23.35%
Join(string, string[]) with 1 element 1327.81% ⚠ 754.88%
Join(string, IEnumerable<string>) with 1 element 352.87% 226.50%
Join(string, List<string>) with 2 elements 104.49% 59.39%
Join(string, string[]) with 2 elements 361.29% 297.61%
Join(string, IEnumerable<string>) with 2 elements 165.40% 101.47%
Join(string, List<string>) with 10 elements 75.99% 34.03%
Join(string, string[]) with 10 elements 421.44% 196.26%
Join(string, IEnumerable<string>) with 10 elements 113.52% 49.99%

⚠ indicates that allocation will occur.

The benchmark results for the udaken/ZString@6b94c72 are detailed below.

Method Mean Error Gen 0 Gen 1 Gen 2 Allocated
JoinEmptyList 17.441 ns NA 0.0048 - - 40 B
ZJoinEmptyList 4.136 ns NA - - - -
JoinList1 25.531 ns NA 0.0048 - - 40 B
ZJoinList1 6.585 ns NA - - - -
JoinArray1 3.665 ns NA - - - -
ZJoinArray1 27.358 ns NA - - - -
JoinEnumerable1 23.882 ns NA 0.0048 - - 40 B
ZJoinEnumerable1 56.520 ns NA 0.0162 - - 136 B
JoinList2 95.549 ns NA 0.0248 - - 208 B
ZJoinList2 61.030 ns NA 0.0200 - - 168 B
JoinArray2 26.032 ns NA 0.0201 - - 168 B
ZJoinArray2 75.796 ns NA 0.0200 - - 168 B
JoinEnumerable2 72.158 ns NA 0.0248 - - 208 B
ZJoinEnumerable2 82.503 ns NA 0.0248 - - 208 B
JoinList10 519.987 ns NA 0.2842 0.0019 - 2384 B
ZJoinList10 193.093 ns NA 0.0908 0.0002 - 760 B
JoinArray10 108.597 ns NA 0.0908 0.0002 - 760 B
ZJoinArray10 184.746 ns NA 0.0908 0.0002 - 760 B
JoinEnumerable10 426.553 ns NA 0.2847 0.0024 - 2384 B
ZJoinEnumerable10 217.014 ns NA 0.0956 0.0002 - 800 B

from zstring.

neuecc avatar neuecc commented on July 23, 2024

I've released 2.1.3, thanks for your great contribution.

from zstring.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.