Last active
March 17, 2022 07:09
-
-
Save joseluisq/6ee3876dc64561ffa14b to your computer and use it in GitHub Desktop.
Revisions
-
joseluisq revised this gist
Aug 18, 2016 . 1 changed file with 0 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -40,5 +40,3 @@ Buffer size of 100: stream_get_line: 0.332s fgets: 0.368s ``` -
joseluisq revised this gist
Aug 18, 2016 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,4 @@ # Comparative between PHP `stream_get_line` and `fgets` about processing large files > Source: http://ie2.php.net/manual/en/function.fgets.php#113113 -
joseluisq revised this gist
Aug 18, 2016 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,4 @@ # Comparative between PHP `stream_get_line` and `fgets` about large files processing > Source: http://ie2.php.net/manual/en/function.fgets.php#113113 -
joseluisq revised this gist
Aug 18, 2016 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,6 +1,6 @@ # Testing about PHP `stream_get_line` and `fgets` for large files > Source: http://ie2.php.net/manual/en/function.fgets.php#113113 Regarding Leigh Purdie's comment (from 4 years ago) about `stream_get_line` being better for large files, I decided to test this in case it was optimized since then and I found out that Leigh's comment is just completely incorrect `fgets` actually has a small amount of better performance, but the test Leigh did was not set up to produce good results. @@ -41,4 +41,4 @@ stream_get_line: 0.332s fgets: 0.368s ``` Source: http://ie2.php.net/manual/en/function.fgets.php#113113 -
joseluisq revised this gist
Mar 9, 2016 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,4 @@ # Testing about PHP `stream_get_line` and `fgets` for large files > From http://ie2.php.net/manual/en/function.fgets.php#113113 -
joseluisq revised this gist
Mar 9, 2016 . 1 changed file with 5 additions and 9 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,9 +1,9 @@ # Testing about PHP `stream_get_line` for process large files > From http://ie2.php.net/manual/en/function.fgets.php#113113 Regarding Leigh Purdie's comment (from 4 years ago) about `stream_get_line` being better for large files, I decided to test this in case it was optimized since then and I found out that Leigh's comment is just completely incorrect `fgets` actually has a small amount of better performance, but the test Leigh did was not set up to produce good results. The suggested test was: @@ -19,11 +19,7 @@ $ time yes "This is a test line" | head -1000000 | php -r '$fp=fopen("php://stdi 0m7.392s ``` The reason this is invalid is because the buffer size of 65535 is completely unnecessary piping the output of "yes 'this is a test line'" in to PHP makes each line 19 characters plus the delimiter so while I don't know why `stream_get_line` performs better with an oversize buffer, if both buffer sizes are correct, or default, they have a negligable performance difference - although notably, `stream_get_line` is consistent - however if you're thinking of switching, make sure to be aware of the difference between the two functions, that `stream_get_line` does NOT append the delimiter, and `fgets` DOES append the delimiter. Here are the results on one of my servers: @@ -45,4 +41,4 @@ stream_get_line: 0.332s fgets: 0.368s ``` Source http://ie2.php.net/manual/en/function.fgets.php#113113 -
joseluisq created this gist
Mar 9, 2016 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,48 @@ # Testing about PHP `stream_get_line` for process large files > From http://ie2.php.net/manual/es/function.fgets.php#113113 Regarding Leigh Purdie's comment (from 4 years ago) about stream_get_line being better for large files, I decided to test this in case it was optimized since then and I found out that Leigh's comment is just completely incorrect fgets actually has a small amount of better performance, but the test Leigh did was not set up to produce good results. The suggested test was: ```sh $ time yes "This is a test line" | head -1000000 | php -r '$fp=fopen("php://stdin","r"); while($line=stream_get_line($fp,65535,"\n")) { 1; } fclose($fp);' 0m1.616s ``` ```sh $ time yes "This is a test line" | head -1000000 | php -r '$fp=fopen("php://stdin","r"); while($line=fgets($fp,65535)) { 1; } fclose($fp);' 0m7.392s ``` The reason this is invalid is because the buffer size of 65535 is completely unnecessary piping the output of "yes 'this is a test line'" in to PHP makes each line 19 characters plus the delimiter so while I don't know why stream_get_line performs better with an oversize buffer, if both buffer sizes are correct, or default, they have a negligable performance difference - although notably, stream_get_line is consistent - however if you're thinking of switching, make sure to be aware of the difference between the two functions, that stream_get_line does NOT append the delimiter, and fgets DOES append the delimiter Here are the results on one of my servers: ```sh Buffer size 65535 stream_get_line: 0.340s fgets: 2.392s Buffer size of 1024 stream_get_line: 0m0.348s fgets: 0.404s Buffer size of 8192 (the default for both) stream_get_line: 0.348s fgets: 0.552s Buffer size of 100: stream_get_line: 0.332s fgets: 0.368s ``` Source http://ie2.php.net/manual/es/function.fgets.php#113113