27
27
use function array_merge ;
28
28
use function file_put_contents ;
29
29
use function is_string ;
30
+ use function microtime ;
30
31
use function spl_autoload_register ;
32
+ use function sprintf ;
31
33
use function var_export ;
32
34
33
35
use const ARRAY_FILTER_USE_BOTH ;
@@ -86,9 +88,11 @@ public static function onPostAutoloadDump(Event $event): void
86
88
assert (is_string ($ vendorDir ));
87
89
$ filepath = "$ vendorDir/attributes.php " ;
88
90
91
+ $ start = microtime (true );
89
92
$ io ->write ('<info>Generating attributes file</info> ' );
90
93
self ::dump ($ event ->getComposer (), $ io , $ filepath );
91
- $ io ->write ('<info>Generated attributes file</info> ' );
94
+ $ elapsed = self ::renderElapsedTime ($ start );
95
+ $ io ->write ("<info>Generated attributes file in $ elapsed</info> " );
92
96
}
93
97
94
98
public static function dump (
@@ -101,24 +105,46 @@ public static function dump(
101
105
$ autoloadsBuilder ??= new AutoloadsBuilder ();
102
106
$ classMapBuilder ??= new ClassMapBuilder ();
103
107
108
+ $ start = microtime (true );
104
109
$ autoloads = $ autoloadsBuilder ->buildAutoloads ($ composer );
110
+ $ elapsed = self ::renderElapsedTime ($ start );
111
+ $ io ->debug ("Generating attributes file: built autoloads in $ elapsed " );
112
+
113
+ $ start = microtime (true );
105
114
$ classMap = $ classMapBuilder ->buildClassMap ($ autoloads );
115
+ $ elapsed = self ::renderElapsedTime ($ start );
116
+ $ io ->debug ("Generating attributes file: built class map in $ elapsed " );
106
117
107
118
self ::setupAutoload ($ classMap );
108
119
120
+ $ start = microtime (true );
109
121
$ filter = self ::buildClassMapFilter ($ composer );
110
122
$ classMap = array_filter (
111
123
$ classMap ,
112
124
fn ($ class , $ filepath ) => $ filter ->filter ($ class , $ filepath , $ io ),
113
125
ARRAY_FILTER_USE_BOTH
114
126
);
127
+ $ elapsed = self ::renderElapsedTime ($ start );
128
+ $ io ->debug ("Generating attributes file: filtered class map in $ elapsed " );
115
129
130
+ $ start = microtime (true );
116
131
$ collection = self ::collectAttributes ($ classMap , $ io );
132
+ $ elapsed = self ::renderElapsedTime ($ start );
133
+ $ io ->debug ("Generating attributes file: collected attributes in $ elapsed " );
134
+
135
+ $ start = microtime (true );
117
136
$ code = self ::render ($ collection );
137
+ $ elapsed = self ::renderElapsedTime ($ start );
138
+ $ io ->debug ("Generating attributes file: rendered code in $ elapsed " );
118
139
119
140
file_put_contents ($ filepath , $ code );
120
141
}
121
142
143
+ private static function renderElapsedTime (float $ start ): string
144
+ {
145
+ return sprintf ("%.03f ms " , (microtime (true ) - $ start ) * 1000 );
146
+ }
147
+
122
148
/**
123
149
* @param array<class-string, non-empty-string> $classMap
124
150
*/
0 commit comments