From 86264c22cc3158803111ca15a245ad60ab9f5eab Mon Sep 17 00:00:00 2001 From: irhen Date: Wed, 28 Mar 2018 19:28:12 +0300 Subject: [PATCH] benchmarks made easier to understand --- benchmarks/lib/AppendAndPrependBench.php | 49 -------- benchmarks/lib/ArrayBench.php | 33 ------ benchmarks/lib/AtAndBetweenBench.php | 25 +++++ benchmarks/lib/BooleansBench.php | 65 ----------- benchmarks/lib/CamelCaseBench.php | 25 +++++ benchmarks/lib/CaseTogglingBench.php | 81 -------------- benchmarks/lib/CharsBench.php | 17 +++ benchmarks/lib/CountAndLengthBench.php | 20 +--- benchmarks/lib/DelimitersBench.php | 33 ++++++ benchmarks/lib/EnsureBench.php | 25 +++++ .../{GetBench.php => FirstAndLastBench.php} | 2 +- benchmarks/lib/HumanizeAndSlugifyBench.php | 25 +++++ benchmarks/lib/IndexOfBench.php | 25 +++++ benchmarks/lib/InsertBench.php | 17 +++ benchmarks/lib/IsAlphaBench.php | 25 +++++ benchmarks/lib/IsBlankBench.php | 17 +++ benchmarks/lib/IsHexadecimalBench.php | 17 +++ benchmarks/lib/IsJsonBench.php | 17 +++ ...onsBench.php => IsOrHasLowerCaseBench.php} | 18 +-- benchmarks/lib/IsOrHasUpperCaseBench.php | 25 +++++ benchmarks/lib/IsSerializedOrBase64Bench.php | 25 +++++ benchmarks/lib/LinesBench.php | 17 +++ benchmarks/lib/LongestCommonSubstrBench.php | 33 ++++++ ...ansBench.php => PrefixesBooleansBench.php} | 18 +-- benchmarks/lib/RemoveBench.php | 26 +++++ benchmarks/lib/RepeatBench.php | 17 +++ benchmarks/lib/ShuffleAndReverseBench.php | 25 +++++ benchmarks/lib/SliceAndSubstrBench.php | 25 +++++ benchmarks/lib/SplitBench.php | 17 +++ benchmarks/lib/StringMutatorsBench.php | 105 ------------------ ...hp => StripAndCollapseWhitespaceBench.php} | 18 +-- benchmarks/lib/SubstrBench.php | 81 -------------- benchmarks/lib/SuffixesBooleansBench.php | 25 +++++ benchmarks/lib/SurroundBench.php | 17 +++ benchmarks/lib/SwapCaseBench.php | 17 +++ benchmarks/lib/TidyBench.php | 17 +++ benchmarks/lib/TitleCaseBench.php | 25 +++++ benchmarks/lib/ToAsciiBench.php | 17 +++ benchmarks/lib/ToLowerCaseBench.php | 25 +++++ benchmarks/lib/ToTabsAndToSpacesBench.php | 25 +++++ benchmarks/lib/ToUpperCaseBench.php | 25 +++++ benchmarks/lib/TruncateBench.php | 25 +++++ 42 files changed, 702 insertions(+), 484 deletions(-) delete mode 100644 benchmarks/lib/ArrayBench.php create mode 100644 benchmarks/lib/AtAndBetweenBench.php delete mode 100644 benchmarks/lib/BooleansBench.php create mode 100644 benchmarks/lib/CamelCaseBench.php delete mode 100644 benchmarks/lib/CaseTogglingBench.php create mode 100644 benchmarks/lib/CharsBench.php create mode 100644 benchmarks/lib/DelimitersBench.php create mode 100644 benchmarks/lib/EnsureBench.php rename benchmarks/lib/{GetBench.php => FirstAndLastBench.php} (96%) create mode 100644 benchmarks/lib/HumanizeAndSlugifyBench.php create mode 100644 benchmarks/lib/IndexOfBench.php create mode 100644 benchmarks/lib/InsertBench.php create mode 100644 benchmarks/lib/IsAlphaBench.php create mode 100644 benchmarks/lib/IsBlankBench.php create mode 100644 benchmarks/lib/IsHexadecimalBench.php create mode 100644 benchmarks/lib/IsJsonBench.php rename benchmarks/lib/{CaseQuestionsBench.php => IsOrHasLowerCaseBench.php} (52%) create mode 100644 benchmarks/lib/IsOrHasUpperCaseBench.php create mode 100644 benchmarks/lib/IsSerializedOrBase64Bench.php create mode 100644 benchmarks/lib/LinesBench.php create mode 100644 benchmarks/lib/LongestCommonSubstrBench.php rename benchmarks/lib/{SuffixesAnsPrefixesBooleansBench.php => PrefixesBooleansBench.php} (52%) create mode 100644 benchmarks/lib/RemoveBench.php create mode 100644 benchmarks/lib/RepeatBench.php create mode 100644 benchmarks/lib/ShuffleAndReverseBench.php create mode 100644 benchmarks/lib/SliceAndSubstrBench.php create mode 100644 benchmarks/lib/SplitBench.php delete mode 100644 benchmarks/lib/StringMutatorsBench.php rename benchmarks/lib/{WhitespaceRelatedBench.php => StripAndCollapseWhitespaceBench.php} (55%) delete mode 100644 benchmarks/lib/SubstrBench.php create mode 100644 benchmarks/lib/SuffixesBooleansBench.php create mode 100644 benchmarks/lib/SurroundBench.php create mode 100644 benchmarks/lib/SwapCaseBench.php create mode 100644 benchmarks/lib/TidyBench.php create mode 100644 benchmarks/lib/TitleCaseBench.php create mode 100644 benchmarks/lib/ToAsciiBench.php create mode 100644 benchmarks/lib/ToLowerCaseBench.php create mode 100644 benchmarks/lib/ToTabsAndToSpacesBench.php create mode 100644 benchmarks/lib/ToUpperCaseBench.php create mode 100644 benchmarks/lib/TruncateBench.php diff --git a/benchmarks/lib/AppendAndPrependBench.php b/benchmarks/lib/AppendAndPrependBench.php index 5231543..558d4b2 100644 --- a/benchmarks/lib/AppendAndPrependBench.php +++ b/benchmarks/lib/AppendAndPrependBench.php @@ -7,22 +7,6 @@ class AppendAndPrependBench { - public function bench_ensure_left_Str() { - (new Str('2'))->ensureLeft('1'); - } - - public function bench_ensure_left_Stringy() { - (new Stringy('2'))->ensureLeft('1'); - } - - public function bench_ensure_right_Str() { - (new Str('2'))->ensureRight('1'); - } - - public function bench_ensure_right_Stringy() { - (new Stringy('2'))->ensureRight('1'); - } - public function bench_append_Str() { (new Str('2'))->append('1'); } @@ -38,37 +22,4 @@ public function bench_prepend_Str() { public function bench_prepend_Stringy() { (new Stringy('2'))->prepend('1'); } - - public function bench_remove_left_Str() { - (new Str('12'))->removeLeft('1'); - } - - public function bench_remove_left_Stringy() { - (new Stringy('12'))->removeLeft('1'); - } - - public function bench_remove_right_Str() { - (new Str('21'))->removeRight('1'); - } - - public function bench_remove_right_Stringy() - { - (new Stringy('21'))->removeRight('1'); - } - - public function bench_insert_Str() { - (new Str('226198'))->insert('1', 4); - } - - public function bench_insert_Stringy() { - (new Stringy('226198'))->insert('1', 4); - } - - public function bench_surround_Str() { - (new Str('2'))->surround('1'); - } - - public function bench_surround_Stringy() { - (new Stringy('2'))->surround('1'); - } } diff --git a/benchmarks/lib/ArrayBench.php b/benchmarks/lib/ArrayBench.php deleted file mode 100644 index b0e37f9..0000000 --- a/benchmarks/lib/ArrayBench.php +++ /dev/null @@ -1,33 +0,0 @@ -chars(); - } - - public function bench_chars_Stringy() { - (new Stringy('Hello world'))->chars(); - } - - public function bench_lines_Str() { - (new Str('Hello world'))->lines(); - } - - public function bench_lines_Stringy() { - (new Stringy('Hello world'))->lines(); - } - - public function bench_split_Str() { - (new Str('Hello world'))->split(' '); - } - - public function bench_split_Stringy() { - (new Stringy('Hello world'))->split(' '); - } -} diff --git a/benchmarks/lib/AtAndBetweenBench.php b/benchmarks/lib/AtAndBetweenBench.php new file mode 100644 index 0000000..d90a279 --- /dev/null +++ b/benchmarks/lib/AtAndBetweenBench.php @@ -0,0 +1,25 @@ +between(2, 4); + } + + public function bench_between_Stringy() { + (new Stringy(' hello world '))->between(2, 4); + } + + public function bench_at_Str() { + (new Str(' hello world '))->at(2); + } + + public function bench_at_Stringy() { + (new Stringy(' hello world '))->at(2); + } +} diff --git a/benchmarks/lib/BooleansBench.php b/benchmarks/lib/BooleansBench.php deleted file mode 100644 index e8f848f..0000000 --- a/benchmarks/lib/BooleansBench.php +++ /dev/null @@ -1,65 +0,0 @@ -isSerialized(); - } - - public function bench_is_serialized_Stringy() { - (new Stringy(' hello world '))->isSerialized(); - } - - public function bench_is_json_Str() { - (new Str(' hello world '))->isJson(); - } - - public function bench_is_json_Stringy() { - (new Stringy(' hello world '))->isJson(); - } - - public function bench_is_hexadecimal_Str() { - (new Str(' hello world '))->isHexadecimal(); - } - - public function bench_is_hexadecimal_Stringy() { - (new Stringy(' hello world '))->isHexadecimal(); - } - - public function bench_is_blank_Str() { - (new Str(' hello world '))->isBlank(); - } - - public function bench_is_blank_Stringy() { - (new Stringy(' hello world '))->isBlank(); - } - - public function bench_is_base64_Str() { - (new Str(' hello world '))->isBase64(); - } - - public function bench_is_base64_Stringy() { - (new Stringy(' hello world '))->isBase64(); - } - - public function bench_is_alpha_numeric_Str() { - (new Str(' hello world '))->isAlphanumeric(); - } - - public function bench_is_alpha_numeric_Stringy() { - (new Stringy(' hello world '))->isAlphanumeric(); - } - - public function bench_is_alpha_Str() { - (new Str(' hello world '))->isAlpha(); - } - - public function bench_is_alpha_Stringy() { - (new Stringy(' hello world '))->isAlpha(); - } -} diff --git a/benchmarks/lib/CamelCaseBench.php b/benchmarks/lib/CamelCaseBench.php new file mode 100644 index 0000000..869ba1d --- /dev/null +++ b/benchmarks/lib/CamelCaseBench.php @@ -0,0 +1,25 @@ +upperCamelize(); + } + + public function bench_upper_camelize_Stringy() { + (new Stringy('some string hello'))->upperCamelize(); + } + + public function bench_camelize_Str() { + (new Str('some string hello'))->camelize(); + } + + public function bench_camelize_Stringy() { + (new Stringy('some string hello'))->camelize(); + } +} diff --git a/benchmarks/lib/CaseTogglingBench.php b/benchmarks/lib/CaseTogglingBench.php deleted file mode 100644 index 1d192d9..0000000 --- a/benchmarks/lib/CaseTogglingBench.php +++ /dev/null @@ -1,81 +0,0 @@ -toTitleCase(); - } - - public function bench_to_title_case_Stringy() { - (new Stringy('some string hello'))->toTitleCase(); - } - - public function bench_titleize_Str() { - (new Str('some string hello'))->titleize(); - } - - public function bench_titleize_Stringy() { - (new Stringy('some string hello'))->titleize(); - } - - public function bench_upper_camelize_Str() { - (new Str('some string hello'))->upperCamelize(); - } - - public function bench_upper_camelize_Stringy() { - (new Stringy('some string hello'))->upperCamelize(); - } - - public function bench_camelize_Str() { - (new Str('some string hello'))->camelize(); - } - - public function bench_camelize_Stringy() { - (new Stringy('some string hello'))->camelize(); - } - - public function bench_swap_case_Str() { - (new Str('hElLo'))->swapCase(); - } - - public function bench_swap_case_Stringy() { - (new Stringy('hElLo'))->swapCase(); - } - - public function bench_upper_case_first_Str() { - (new Str('hello'))->upperCaseFirst(); - } - - public function bench_upper_case_first_Stringy() { - (new Stringy('hello'))->upperCaseFirst(); - } - - public function bench_lower_case_first_Str() { - (new Str('HELLO'))->lowerCaseFirst(); - } - - public function bench_lower_case_first_Stringy() { - (new Stringy('HELLO'))->lowerCaseFirst(); - } - - public function bench_to_upper_case_Str() { - (new Str('hello'))->toUpperCase(); - } - - public function bench_to_upper_case_Stringy() { - (new Stringy('hello'))->toUpperCase(); - } - - public function bench_to_lower_case_Str() { - (new Str('HELLO'))->toLowerCase(); - } - - public function bench_to_lower_case_Stringy() { - (new Stringy('HELLO'))->toLowerCase(); - } -} diff --git a/benchmarks/lib/CharsBench.php b/benchmarks/lib/CharsBench.php new file mode 100644 index 0000000..6dd4301 --- /dev/null +++ b/benchmarks/lib/CharsBench.php @@ -0,0 +1,17 @@ +chars(); + } + + public function bench_chars_Stringy() { + (new Stringy('Hello world'))->chars(); + } +} diff --git a/benchmarks/lib/CountAndLengthBench.php b/benchmarks/lib/CountAndLengthBench.php index bf3f26f..355d5b3 100644 --- a/benchmarks/lib/CountAndLengthBench.php +++ b/benchmarks/lib/CountAndLengthBench.php @@ -15,27 +15,11 @@ public function bench_length_Stringy() { (new Stringy('Hello world'))->length(); } - public function bench_indexOf_Str() { - (new Str('Hello world'))->indexOf('l'); - } - - public function bench_indexOf_Stringy() { - (new Stringy('Hello world'))->indexOf('l'); - } - - public function bench_indexOfLast_Str() { - (new Str('Hello world'))->indexOfLast('l'); - } - - public function bench_indexOfLast_Stringy() { - (new Stringy('Hello world'))->indexOfLast('l'); - } - - public function bench_count_Str() { + public function bench_count_substr_Str() { (new Str('HelLo wOrld'))->countSubstr('l', false); } - public function bench_count_Stringy() { + public function bench_count_substr_Stringy() { (new Stringy('HelLo wOrld'))->countSubstr('l', false); } } diff --git a/benchmarks/lib/DelimitersBench.php b/benchmarks/lib/DelimitersBench.php new file mode 100644 index 0000000..1ddb83c --- /dev/null +++ b/benchmarks/lib/DelimitersBench.php @@ -0,0 +1,33 @@ +underscored(); + } + + public function bench_underscored_Stringy() { + (new Stringy(' hello world '))->underscored(); + } + + public function bench_delimit_Str() { + (new Str(' hello world '))->delimit('()'); + } + + public function bench_delimit_Stringy() { + (new Stringy(' hello world '))->delimit('()'); + } + + public function bench_dasherize_Str() { + (new Str(' hello world '))->dasherize(); + } + + public function bench_dasherize_Stringy() { + (new Stringy(' hello world '))->dasherize(); + } +} diff --git a/benchmarks/lib/EnsureBench.php b/benchmarks/lib/EnsureBench.php new file mode 100644 index 0000000..4eb14ef --- /dev/null +++ b/benchmarks/lib/EnsureBench.php @@ -0,0 +1,25 @@ +ensureLeft('1'); + } + + public function bench_ensure_left_Stringy() { + (new Stringy('2'))->ensureLeft('1'); + } + + public function bench_ensure_right_Str() { + (new Str('2'))->ensureRight('1'); + } + + public function bench_ensure_right_Stringy() { + (new Stringy('2'))->ensureRight('1'); + } +} diff --git a/benchmarks/lib/GetBench.php b/benchmarks/lib/FirstAndLastBench.php similarity index 96% rename from benchmarks/lib/GetBench.php rename to benchmarks/lib/FirstAndLastBench.php index 1311fbe..52f3287 100644 --- a/benchmarks/lib/GetBench.php +++ b/benchmarks/lib/FirstAndLastBench.php @@ -5,7 +5,7 @@ use Str\Str; use Stringy\Stringy; -class GetBench +class FirstAndLastBench { public function bench_first_Str() { (new Str('Hello world'))->first(6); diff --git a/benchmarks/lib/HumanizeAndSlugifyBench.php b/benchmarks/lib/HumanizeAndSlugifyBench.php new file mode 100644 index 0000000..8ec2940 --- /dev/null +++ b/benchmarks/lib/HumanizeAndSlugifyBench.php @@ -0,0 +1,25 @@ +slugify(); + } + + public function bench_slugify_Stringy() { + (new Stringy(' hello world '))->slugify(); + } + + public function bench_humanize_Str() { + (new Str(' hello world '))->humanize(); + } + + public function bench_humanize_Stringy() { + (new Stringy(' hello world '))->humanize(); + } +} diff --git a/benchmarks/lib/IndexOfBench.php b/benchmarks/lib/IndexOfBench.php new file mode 100644 index 0000000..7d38812 --- /dev/null +++ b/benchmarks/lib/IndexOfBench.php @@ -0,0 +1,25 @@ +indexOf('l'); + } + + public function bench_indexOf_Stringy() { + (new Stringy('Hello world'))->indexOf('l'); + } + + public function bench_indexOfLast_Str() { + (new Str('Hello world'))->indexOfLast('l'); + } + + public function bench_indexOfLast_Stringy() { + (new Stringy('Hello world'))->indexOfLast('l'); + } +} diff --git a/benchmarks/lib/InsertBench.php b/benchmarks/lib/InsertBench.php new file mode 100644 index 0000000..13538af --- /dev/null +++ b/benchmarks/lib/InsertBench.php @@ -0,0 +1,17 @@ +insert('1', 4); + } + + public function bench_insert_Stringy() { + (new Stringy('226198'))->insert('1', 4); + } +} diff --git a/benchmarks/lib/IsAlphaBench.php b/benchmarks/lib/IsAlphaBench.php new file mode 100644 index 0000000..d86a945 --- /dev/null +++ b/benchmarks/lib/IsAlphaBench.php @@ -0,0 +1,25 @@ +isAlphanumeric(); + } + + public function bench_is_alpha_numeric_Stringy() { + (new Stringy(' hello world '))->isAlphanumeric(); + } + + public function bench_is_alpha_Str() { + (new Str(' hello world '))->isAlpha(); + } + + public function bench_is_alpha_Stringy() { + (new Stringy(' hello world '))->isAlpha(); + } +} diff --git a/benchmarks/lib/IsBlankBench.php b/benchmarks/lib/IsBlankBench.php new file mode 100644 index 0000000..e4130f6 --- /dev/null +++ b/benchmarks/lib/IsBlankBench.php @@ -0,0 +1,17 @@ +isBlank(); + } + + public function bench_is_blank_Stringy() { + (new Stringy(' hello world '))->isBlank(); + } +} diff --git a/benchmarks/lib/IsHexadecimalBench.php b/benchmarks/lib/IsHexadecimalBench.php new file mode 100644 index 0000000..0819af9 --- /dev/null +++ b/benchmarks/lib/IsHexadecimalBench.php @@ -0,0 +1,17 @@ +isHexadecimal(); + } + + public function bench_is_hexadecimal_Stringy() { + (new Stringy(' hello world '))->isHexadecimal(); + } +} diff --git a/benchmarks/lib/IsJsonBench.php b/benchmarks/lib/IsJsonBench.php new file mode 100644 index 0000000..85c4ce8 --- /dev/null +++ b/benchmarks/lib/IsJsonBench.php @@ -0,0 +1,17 @@ +isJson(); + } + + public function bench_is_json_Stringy() { + (new Stringy(' hello world '))->isJson(); + } +} diff --git a/benchmarks/lib/CaseQuestionsBench.php b/benchmarks/lib/IsOrHasLowerCaseBench.php similarity index 52% rename from benchmarks/lib/CaseQuestionsBench.php rename to benchmarks/lib/IsOrHasLowerCaseBench.php index db68c92..6b69282 100644 --- a/benchmarks/lib/CaseQuestionsBench.php +++ b/benchmarks/lib/IsOrHasLowerCaseBench.php @@ -5,16 +5,8 @@ use Str\Str; use Stringy\Stringy; -class CaseQuestionsBench +class IsOrHasLowerCaseBench { - public function bench_is_upper_case_Str() { - (new Str(' hello world '))->isUpperCase(); - } - - public function bench_is_upper_case_Stringy() { - (new Stringy(' hello world '))->isUpperCase(); - } - public function bench_is_lower_case_Str() { (new Str(' hello world '))->isLowerCase(); } @@ -23,14 +15,6 @@ public function bench_is_lower_case_Stringy() { (new Stringy(' hello world '))->isLowerCase(); } - public function bench_has_upper_case_Str() { - (new Str(' hello world '))->hasUpperCase(); - } - - public function bench_has_upper_case_Stringy() { - (new Stringy(' hello world '))->hasUpperCase(); - } - public function bench_has_lower_case_Str() { (new Str(' hello world '))->hasLowerCase(); } diff --git a/benchmarks/lib/IsOrHasUpperCaseBench.php b/benchmarks/lib/IsOrHasUpperCaseBench.php new file mode 100644 index 0000000..6027f2d --- /dev/null +++ b/benchmarks/lib/IsOrHasUpperCaseBench.php @@ -0,0 +1,25 @@ +isUpperCase(); + } + + public function bench_is_upper_case_Stringy() { + (new Stringy(' hello world '))->isUpperCase(); + } + + public function bench_has_upper_case_Str() { + (new Str(' hello world '))->hasUpperCase(); + } + + public function bench_has_upper_case_Stringy() { + (new Stringy(' hello world '))->hasUpperCase(); + } +} diff --git a/benchmarks/lib/IsSerializedOrBase64Bench.php b/benchmarks/lib/IsSerializedOrBase64Bench.php new file mode 100644 index 0000000..ede7f41 --- /dev/null +++ b/benchmarks/lib/IsSerializedOrBase64Bench.php @@ -0,0 +1,25 @@ +isSerialized(); + } + + public function bench_is_serialized_Stringy() { + (new Stringy(' hello world '))->isSerialized(); + } + + public function bench_is_base64_Str() { + (new Str(' hello world '))->isBase64(); + } + + public function bench_is_base64_Stringy() { + (new Stringy(' hello world '))->isBase64(); + } +} diff --git a/benchmarks/lib/LinesBench.php b/benchmarks/lib/LinesBench.php new file mode 100644 index 0000000..ca75169 --- /dev/null +++ b/benchmarks/lib/LinesBench.php @@ -0,0 +1,17 @@ +lines(); + } + + public function bench_lines_Stringy() { + (new Stringy('Hello world'))->lines(); + } +} diff --git a/benchmarks/lib/LongestCommonSubstrBench.php b/benchmarks/lib/LongestCommonSubstrBench.php new file mode 100644 index 0000000..40c41d6 --- /dev/null +++ b/benchmarks/lib/LongestCommonSubstrBench.php @@ -0,0 +1,33 @@ +longestCommonSubstring(' helloworld'); + } + + public function bench_longest_common_substring_Stringy() { + (new Stringy(' hello world '))->longestCommonSubstring(' helloworld'); + } + + public function bench_longest_common_suffix_Str() { + (new Str(' hello world '))->longestCommonSuffix(' hello'); + } + + public function bench_longest_common_suffix_Stringy() { + (new Stringy(' hello world '))->longestCommonSuffix(' hello'); + } + + public function bench_longest_common_prefix_Str() { + (new Str(' hello world '))->longestCommonPrefix(' hello'); + } + + public function bench_longest_common_prefix_Stringy() { + (new Stringy(' hello world '))->longestCommonPrefix(' hello'); + } +} diff --git a/benchmarks/lib/SuffixesAnsPrefixesBooleansBench.php b/benchmarks/lib/PrefixesBooleansBench.php similarity index 52% rename from benchmarks/lib/SuffixesAnsPrefixesBooleansBench.php rename to benchmarks/lib/PrefixesBooleansBench.php index 948ab5d..b5d2262 100644 --- a/benchmarks/lib/SuffixesAnsPrefixesBooleansBench.php +++ b/benchmarks/lib/PrefixesBooleansBench.php @@ -5,16 +5,8 @@ use Str\Str; use Stringy\Stringy; -class SuffixesAnsPrefixesBooleansBench +class PrefixesBooleansBench { - public function bench_ends_with_any_Str() { - (new Str(' hello world '))->endsWithAny(['he', 'lo']); - } - - public function bench_ends_with_any_Stringy() { - (new Stringy(' hello world '))->endsWithAny(['he', 'lo']); - } - public function bench_starts_with_any_Str() { (new Str(' hello world '))->startsWithAny(['he', 'lo']); } @@ -23,14 +15,6 @@ public function bench_starts_with_any_Stringy() { (new Stringy(' hello world '))->startsWithAny(['he', 'lo']); } - public function bench_ends_with_Str() { - (new Str(' hello world '))->endsWith('he'); - } - - public function bench_ends_with_Stringy() { - (new Stringy(' hello world '))->endsWith('he'); - } - public function bench_starts_with_Str() { (new Str(' hello world '))->startsWith('he'); } diff --git a/benchmarks/lib/RemoveBench.php b/benchmarks/lib/RemoveBench.php new file mode 100644 index 0000000..d17d2fa --- /dev/null +++ b/benchmarks/lib/RemoveBench.php @@ -0,0 +1,26 @@ +removeLeft('1'); + } + + public function bench_remove_left_Stringy() { + (new Stringy('12'))->removeLeft('1'); + } + + public function bench_remove_right_Str() { + (new Str('21'))->removeRight('1'); + } + + public function bench_remove_right_Stringy() + { + (new Stringy('21'))->removeRight('1'); + } +} diff --git a/benchmarks/lib/RepeatBench.php b/benchmarks/lib/RepeatBench.php new file mode 100644 index 0000000..516e82d --- /dev/null +++ b/benchmarks/lib/RepeatBench.php @@ -0,0 +1,17 @@ +repeat(2); + } + + public function bench_repeat_Stringy() { + (new Stringy(' hello world '))->repeat(2); + } +} diff --git a/benchmarks/lib/ShuffleAndReverseBench.php b/benchmarks/lib/ShuffleAndReverseBench.php new file mode 100644 index 0000000..5b98a1c --- /dev/null +++ b/benchmarks/lib/ShuffleAndReverseBench.php @@ -0,0 +1,25 @@ +reverse(); + } + + public function bench_reverse_Stringy() { + (new Stringy(' hello world '))->reverse(); + } + + public function bench_shuffle_Str() { + (new Str(' hello world '))->shuffle(); + } + + public function bench_shuffle_Stringy() { + (new Stringy(' hello world '))->shuffle(); + } +} diff --git a/benchmarks/lib/SliceAndSubstrBench.php b/benchmarks/lib/SliceAndSubstrBench.php new file mode 100644 index 0000000..52c8621 --- /dev/null +++ b/benchmarks/lib/SliceAndSubstrBench.php @@ -0,0 +1,25 @@ +slice(2); + } + + public function bench_slice_Stringy() { + (new Stringy(' hello world '))->slice(2); + } + + public function bench_substr_Str() { + (new Str(' hello world '))->substr(2); + } + + public function bench_substr_Stringy() { + (new Stringy(' hello world '))->substr(2); + } +} diff --git a/benchmarks/lib/SplitBench.php b/benchmarks/lib/SplitBench.php new file mode 100644 index 0000000..61003d4 --- /dev/null +++ b/benchmarks/lib/SplitBench.php @@ -0,0 +1,17 @@ +split(' '); + } + + public function bench_split_Stringy() { + (new Stringy('Hello world'))->split(' '); + } +} diff --git a/benchmarks/lib/StringMutatorsBench.php b/benchmarks/lib/StringMutatorsBench.php deleted file mode 100644 index 09aabd6..0000000 --- a/benchmarks/lib/StringMutatorsBench.php +++ /dev/null @@ -1,105 +0,0 @@ -underscored(); - } - - public function bench_underscored_Stringy() { - (new Stringy(' hello world '))->underscored(); - } - - public function bench_tidy_Str() { - (new Str(' hello world '))->tidy(); - } - - public function bench_tidy_Stringy() { - (new Stringy(' hello world '))->tidy(); - } - - public function bench_to_ascii_Str() { - (new Str(' hello world '))->toAscii(); - } - - public function bench_to_ascii_Stringy() { - (new Stringy(' hello world '))->toAscii(); - } - - public function bench_slugify_Str() { - (new Str(' hello world '))->slugify(); - } - - public function bench_slugify_Stringy() { - (new Stringy(' hello world '))->slugify(); - } - - public function bench_truncate_Str() { - (new Str(' hello world '))->truncate(2, 'duh'); - } - - public function bench_truncate_Stringy() { - (new Stringy(' hello world '))->truncate(2, 'duh'); - } - - public function bench_safe_truncate_Str() { - (new Str(' hello world '))->safeTruncate(2, 'duh'); - } - - public function bench_safe_truncate_Stringy() { - (new Stringy(' hello world '))->safeTruncate(2, 'duh'); - } - - public function bench_humanize_Str() { - (new Str(' hello world '))->humanize(); - } - - public function bench_humanize_Stringy() { - (new Stringy(' hello world '))->humanize(); - } - - public function bench_delimit_Str() { - (new Str(' hello world '))->delimit('()'); - } - - public function bench_delimit_Stringy() { - (new Stringy(' hello world '))->delimit('()'); - } - - public function bench_dasherize_Str() { - (new Str(' hello world '))->dasherize(); - } - - public function bench_dasherize_Stringy() { - (new Stringy(' hello world '))->dasherize(); - } - - public function bench_reverse_Str() { - (new Str(' hello world '))->reverse(); - } - - public function bench_reverse_Stringy() { - (new Stringy(' hello world '))->reverse(); - } - - public function bench_repeat_Str() { - (new Str(' hello world '))->repeat(2); - } - - public function bench_repeat_Stringy() { - (new Stringy(' hello world '))->repeat(2); - } - - public function bench_shuffle_Str() { - (new Str(' hello world '))->shuffle(); - } - - public function bench_shuffle_Stringy() { - (new Stringy(' hello world '))->shuffle(); - } -} diff --git a/benchmarks/lib/WhitespaceRelatedBench.php b/benchmarks/lib/StripAndCollapseWhitespaceBench.php similarity index 55% rename from benchmarks/lib/WhitespaceRelatedBench.php rename to benchmarks/lib/StripAndCollapseWhitespaceBench.php index 77548b3..761cdb5 100644 --- a/benchmarks/lib/WhitespaceRelatedBench.php +++ b/benchmarks/lib/StripAndCollapseWhitespaceBench.php @@ -5,24 +5,8 @@ use Str\Str; use Stringy\Stringy; -class WhitespaceRelatedBench +class StripAndCollapseWhitespaceBench { - public function bench_to_tabs_Str() { - (new Str(' hello world '))->toTabs(); - } - - public function bench_to_tabs_Stringy() { - (new Stringy(' hello world '))->toTabs(); - } - - public function bench_to_spaces_Str() { - (new Str(' hello world '))->toSpaces(); - } - - public function bench_to_spaces_Stringy() { - (new Stringy(' hello world '))->toSpaces(); - } - public function bench_strip_whitespace_Str() { (new Str(' hello world '))->stripWhitespace(); } diff --git a/benchmarks/lib/SubstrBench.php b/benchmarks/lib/SubstrBench.php deleted file mode 100644 index 93e2ee3..0000000 --- a/benchmarks/lib/SubstrBench.php +++ /dev/null @@ -1,81 +0,0 @@ -slice(2); - } - - public function bench_slice_Stringy() { - (new Stringy(' hello world '))->slice(2); - } - - public function bench_longest_common_substring_Str() { - (new Str(' hello world '))->longestCommonSubstring(' helloworld'); - } - - public function bench_longest_common_substring_Stringy() { - (new Stringy(' hello world '))->longestCommonSubstring(' helloworld'); - } - - public function bench_longest_common_suffix_Str() { - (new Str(' hello world '))->longestCommonSuffix(' hello'); - } - - public function bench_longest_common_suffix_Stringy() { - (new Stringy(' hello world '))->longestCommonSuffix(' hello'); - } - - public function bench_longest_common_prefix_Str() { - (new Str(' hello world '))->longestCommonPrefix(' hello'); - } - - public function bench_longest_common_prefix_Stringy() { - (new Stringy(' hello world '))->longestCommonPrefix(' hello'); - } - - public function bench_between_Str() { - (new Str(' hello world '))->between(2, 4); - } - - public function bench_between_Stringy() { - (new Stringy(' hello world '))->between(2, 4); - } - - public function bench_last_Str() { - (new Str(' hello world '))->last(2); - } - - public function bench_last_Stringy() { - (new Stringy(' hello world '))->last(2); - } - - public function bench_first_Str() { - (new Str(' hello world '))->first(2); - } - - public function bench_first_Stringy() { - (new Stringy(' hello world '))->first(2); - } - - public function bench_at_Str() { - (new Str(' hello world '))->at(2); - } - - public function bench_at_Stringy() { - (new Stringy(' hello world '))->at(2); - } - - public function bench_substr_Str() { - (new Str(' hello world '))->substr(2); - } - - public function bench_substr_Stringy() { - (new Stringy(' hello world '))->substr(2); - } -} diff --git a/benchmarks/lib/SuffixesBooleansBench.php b/benchmarks/lib/SuffixesBooleansBench.php new file mode 100644 index 0000000..94fefd6 --- /dev/null +++ b/benchmarks/lib/SuffixesBooleansBench.php @@ -0,0 +1,25 @@ +endsWithAny(['he', 'lo']); + } + + public function bench_ends_with_any_Stringy() { + (new Stringy(' hello world '))->endsWithAny(['he', 'lo']); + } + + public function bench_ends_with_Str() { + (new Str(' hello world '))->endsWith('he'); + } + + public function bench_ends_with_Stringy() { + (new Stringy(' hello world '))->endsWith('he'); + } +} diff --git a/benchmarks/lib/SurroundBench.php b/benchmarks/lib/SurroundBench.php new file mode 100644 index 0000000..d850be7 --- /dev/null +++ b/benchmarks/lib/SurroundBench.php @@ -0,0 +1,17 @@ +surround('1'); + } + + public function bench_surround_Stringy() { + (new Stringy('2'))->surround('1'); + } +} diff --git a/benchmarks/lib/SwapCaseBench.php b/benchmarks/lib/SwapCaseBench.php new file mode 100644 index 0000000..b28e378 --- /dev/null +++ b/benchmarks/lib/SwapCaseBench.php @@ -0,0 +1,17 @@ +swapCase(); + } + + public function bench_swap_case_Stringy() { + (new Stringy('hElLo'))->swapCase(); + } +} diff --git a/benchmarks/lib/TidyBench.php b/benchmarks/lib/TidyBench.php new file mode 100644 index 0000000..e870822 --- /dev/null +++ b/benchmarks/lib/TidyBench.php @@ -0,0 +1,17 @@ +tidy(); + } + + public function bench_tidy_Stringy() { + (new Stringy(' hello world '))->tidy(); + } +} diff --git a/benchmarks/lib/TitleCaseBench.php b/benchmarks/lib/TitleCaseBench.php new file mode 100644 index 0000000..6be65a7 --- /dev/null +++ b/benchmarks/lib/TitleCaseBench.php @@ -0,0 +1,25 @@ +toTitleCase(); + } + + public function bench_to_title_case_Stringy() { + (new Stringy('some string hello'))->toTitleCase(); + } + + public function bench_titleize_Str() { + (new Str('some string hello'))->titleize(); + } + + public function bench_titleize_Stringy() { + (new Stringy('some string hello'))->titleize(); + } +} diff --git a/benchmarks/lib/ToAsciiBench.php b/benchmarks/lib/ToAsciiBench.php new file mode 100644 index 0000000..7697e37 --- /dev/null +++ b/benchmarks/lib/ToAsciiBench.php @@ -0,0 +1,17 @@ +toAscii(); + } + + public function bench_to_ascii_Stringy() { + (new Stringy(' hello world '))->toAscii(); + } +} diff --git a/benchmarks/lib/ToLowerCaseBench.php b/benchmarks/lib/ToLowerCaseBench.php new file mode 100644 index 0000000..6ac3328 --- /dev/null +++ b/benchmarks/lib/ToLowerCaseBench.php @@ -0,0 +1,25 @@ +lowerCaseFirst(); + } + + public function bench_lower_case_first_Stringy() { + (new Stringy('HELLO'))->lowerCaseFirst(); + } + + public function bench_to_lower_case_Str() { + (new Str('HELLO'))->toLowerCase(); + } + + public function bench_to_lower_case_Stringy() { + (new Stringy('HELLO'))->toLowerCase(); + } +} diff --git a/benchmarks/lib/ToTabsAndToSpacesBench.php b/benchmarks/lib/ToTabsAndToSpacesBench.php new file mode 100644 index 0000000..2d0d752 --- /dev/null +++ b/benchmarks/lib/ToTabsAndToSpacesBench.php @@ -0,0 +1,25 @@ +toTabs(); + } + + public function bench_to_tabs_Stringy() { + (new Stringy(' hello world '))->toTabs(); + } + + public function bench_to_spaces_Str() { + (new Str(' hello world '))->toSpaces(); + } + + public function bench_to_spaces_Stringy() { + (new Stringy(' hello world '))->toSpaces(); + } +} diff --git a/benchmarks/lib/ToUpperCaseBench.php b/benchmarks/lib/ToUpperCaseBench.php new file mode 100644 index 0000000..3aaf441 --- /dev/null +++ b/benchmarks/lib/ToUpperCaseBench.php @@ -0,0 +1,25 @@ +upperCaseFirst(); + } + + public function bench_upper_case_first_Stringy() { + (new Stringy('hello'))->upperCaseFirst(); + } + + public function bench_to_upper_case_Str() { + (new Str('hello'))->toUpperCase(); + } + + public function bench_to_upper_case_Stringy() { + (new Stringy('hello'))->toUpperCase(); + } +} diff --git a/benchmarks/lib/TruncateBench.php b/benchmarks/lib/TruncateBench.php new file mode 100644 index 0000000..15817f3 --- /dev/null +++ b/benchmarks/lib/TruncateBench.php @@ -0,0 +1,25 @@ +truncate(2, 'duh'); + } + + public function bench_truncate_Stringy() { + (new Stringy(' hello world '))->truncate(2, 'duh'); + } + + public function bench_safe_truncate_Str() { + (new Str(' hello world '))->safeTruncate(2, 'duh'); + } + + public function bench_safe_truncate_Stringy() { + (new Stringy(' hello world '))->safeTruncate(2, 'duh'); + } +}