Commit 7508f8b
committed
Improve performance of unpack() with nameless repetitions
We can avoid creating temporary strings, and then reparsing them into
numbers with zend_symtable_update() by using zend_hash_index_update()
directly.
For the following benchmark on an i7-4790:
```php
$file = str_repeat('A', 100000);
for ($i=0;$i<100;$i++) unpack('C*',$file);
```
I get:
```
Benchmark 1: ./sapi/cli/php y.php
Time (mean ± σ): 85.8 ms ± 1.8 ms [User: 74.5 ms, System: 10.4 ms]
Range (min … max): 83.8 ms … 92.4 ms 33 runs
Benchmark 2: ./sapi/cli/php_old y.php
Time (mean ± σ): 318.3 ms ± 2.7 ms [User: 306.7 ms, System: 9.9 ms]
Range (min … max): 314.9 ms … 321.6 ms 10 runs
Summary
./sapi/cli/php y.php ran
3.71 ± 0.08 times faster than ./sapi/cli/php_old y.php
```
On an i7-1185G7 I get:
```
Benchmark 1: ./sapi/cli/php test.php
Time (mean ± σ): 60.1 ms ± 0.7 ms [User: 47.8 ms, System: 12.0 ms]
Range (min … max): 59.2 ms … 63.8 ms 48 runs
Warning: Statistical outliers were detected. Consider re-running this benchmark on a quiet system without any interferences from other programs. It might help to use the '--warmup' or '--prepare' options.
Benchmark 2: ./sapi/cli/php_old test.php
Time (mean ± σ): 220.8 ms ± 2.2 ms [User: 209.6 ms, System: 10.7 ms]
Range (min … max): 218.5 ms … 224.5 ms 13 runs
Summary
./sapi/cli/php test.php ran
3.67 ± 0.06 times faster than ./sapi/cli/php_old test.php
```1 parent cb04226 commit 7508f8b
2 files changed
+19
-17
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
567 | 567 | | |
568 | 568 | | |
569 | 569 | | |
| 570 | + | |
| 571 | + | |
570 | 572 | | |
571 | 573 | | |
572 | 574 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
885 | 885 | | |
886 | 886 | | |
887 | 887 | | |
| 888 | + | |
888 | 889 | | |
889 | 890 | | |
890 | 891 | | |
891 | 892 | | |
892 | 893 | | |
893 | | - | |
| 894 | + | |
| 895 | + | |
| 896 | + | |
894 | 897 | | |
895 | 898 | | |
896 | 899 | | |
| |||
912 | 915 | | |
913 | 916 | | |
914 | 917 | | |
915 | | - | |
916 | 918 | | |
917 | 919 | | |
918 | 920 | | |
| |||
939 | 941 | | |
940 | 942 | | |
941 | 943 | | |
942 | | - | |
943 | 944 | | |
944 | 945 | | |
945 | 946 | | |
| |||
964 | 965 | | |
965 | 966 | | |
966 | 967 | | |
967 | | - | |
968 | 968 | | |
969 | 969 | | |
970 | 970 | | |
| |||
1016 | 1016 | | |
1017 | 1017 | | |
1018 | 1018 | | |
1019 | | - | |
1020 | 1019 | | |
1021 | 1020 | | |
1022 | 1021 | | |
| |||
1026 | 1025 | | |
1027 | 1026 | | |
1028 | 1027 | | |
1029 | | - | |
1030 | 1028 | | |
1031 | 1029 | | |
1032 | 1030 | | |
| |||
1046 | 1044 | | |
1047 | 1045 | | |
1048 | 1046 | | |
1049 | | - | |
1050 | 1047 | | |
1051 | 1048 | | |
1052 | 1049 | | |
| |||
1062 | 1059 | | |
1063 | 1060 | | |
1064 | 1061 | | |
1065 | | - | |
1066 | 1062 | | |
1067 | 1063 | | |
1068 | 1064 | | |
| |||
1082 | 1078 | | |
1083 | 1079 | | |
1084 | 1080 | | |
1085 | | - | |
1086 | | - | |
1087 | 1081 | | |
1088 | 1082 | | |
1089 | 1083 | | |
| |||
1104 | 1098 | | |
1105 | 1099 | | |
1106 | 1100 | | |
1107 | | - | |
1108 | 1101 | | |
1109 | 1102 | | |
1110 | 1103 | | |
| |||
1124 | 1117 | | |
1125 | 1118 | | |
1126 | 1119 | | |
1127 | | - | |
1128 | 1120 | | |
1129 | 1121 | | |
1130 | 1122 | | |
| |||
1143 | 1135 | | |
1144 | 1136 | | |
1145 | 1137 | | |
1146 | | - | |
1147 | 1138 | | |
1148 | 1139 | | |
1149 | 1140 | | |
1150 | 1141 | | |
1151 | 1142 | | |
1152 | | - | |
| 1143 | + | |
1153 | 1144 | | |
1154 | 1145 | | |
1155 | 1146 | | |
| |||
1160 | 1151 | | |
1161 | 1152 | | |
1162 | 1153 | | |
1163 | | - | |
| 1154 | + | |
1164 | 1155 | | |
1165 | 1156 | | |
1166 | 1157 | | |
| |||
1170 | 1161 | | |
1171 | 1162 | | |
1172 | 1163 | | |
1173 | | - | |
| 1164 | + | |
1174 | 1165 | | |
1175 | 1166 | | |
1176 | | - | |
| 1167 | + | |
| 1168 | + | |
| 1169 | + | |
| 1170 | + | |
| 1171 | + | |
| 1172 | + | |
| 1173 | + | |
| 1174 | + | |
| 1175 | + | |
| 1176 | + | |
1177 | 1177 | | |
1178 | 1178 | | |
1179 | 1179 | | |
| |||
0 commit comments