<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<style type="text/css" style="display:none;"> P {margin-top:0;margin-bottom:0;} </style>
</head>
<body dir="ltr">
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
Hi all,</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
I've got some results for Windows on an Intel Core i5-9600K<a href="https://www.amazon.co.uk/gp/product/B07HHLX1R8/ref=ppx_yo_dt_b_search_asin_title?ie=UTF8&psc=1" id="LPlnk846820"></a>; although only with the program Richard attached, not with Steve's modified
 version: <span><a href="https://gist.github.com/DavidTruby/aa885134abcab6746ddef962fd90bfc0" id="LPlnk104200">https://gist.github.com/DavidTruby/aa885134abcab6746ddef962fd90bfc0</a><br>
</span></div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<span><br>
</span></div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<span>The result show that on Windows with msvc std::remove_if is significantly faster in this case (where there are carriage returns). This matches my expectations given how much emphasis Microsoft put on C++ features over C features in their compiler and
 runtime. When using clang on Windows, all 3 implementations are indistinguishable in performance.
<br>
</span></div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<span>Therefore if we're likely to want to optimise for the slow case for Windows since this case is more common there, the remove_if implementation would be a better choice. I don't have any data about what happens if there's no carraige returns on Windows
 though, if Steve could share his modified benchmark then I'd be happy to get those results too.<br>
</span></div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<span><br>
</span></div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<span>Another thing to consider: In a previous email about this topic (<a href="http://lists.llvm.org/pipermail/flang-dev/2020-February/000236.html" id="LPlnk172561">http://lists.llvm.org/pipermail/flang-dev/2020-February/000236.html</a>) Steve mentioned that
 we may need to extend this to normalising other types of line end characters in future. I believe the std::remove_if implementation is trivial to extend to that, whereas it seems the RemoveCarriageReturns implementation relies on the fact that you're only
 looking for one character to normalise? Please correct me if I'm wrong here.</span></div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<span><br>
</span></div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<span>Thanks</span></div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<span>David Truby<br>
</span></div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<span><br>
</span></div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<span></span><br>
</div>
<div id="appendonsend"></div>
<hr style="display:inline-block;width:98%" tabindex="-1">
<div id="divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" style="font-size:11pt" color="#000000"><b>From:</b> flang-dev <flang-dev-bounces@lists.llvm.org> on behalf of Steve Scalpone via flang-dev <flang-dev@lists.llvm.org><br>
<b>Sent:</b> 03 April 2020 01:19<br>
<b>To:</b> Richard Barton <Richard.Barton@arm.com>; flang-dev@lists.llvm.org <flang-dev@lists.llvm.org><br>
<b>Subject:</b> Re: [flang-dev] FW: Performance of std::remove_if in F18 file I/O</font>
<div> </div>
</div>
<div class="BodyFragment"><font size="2"><span style="font-size:11pt;">
<div class="PlainText">Hi Rich,<br>
<br>
Most systems, including UNIX derivatives, use a single linefeed character (^J, ASCII LF = 0x0a) as an end-of-line marker in source files.  Others (DOS, Windows) use a carriage return / linefeed sequence (0x0d 0x0a).  The f18 compiler normalizes source files
 by removing all of their carriage return characters.<br>
 <br>
I have extended the benchmark to add another path that runs over source code containing no original carriage return characters.  We expect this use case to be the most common outside Windows environments.<br>
 <br>
I posted the test results.  Each set has four runs, each comprising the combination of remove_if and RemoveCarriageReturns with linefeeds and carriage returns.<br>
 <br>
In summary, RemoveCarriageReturns is faster when there actually are no carriage returns to remove.  For cases with carriage returns, RemoveCarriageReturns is faster on x86 Linux, about the same on macOS, and slower on aarch64.<br>
 <br>
Linux x86-64<br>
<a href="https://gist.github.com/sscalpone/11f58f248cc2a984be80a6b0867836ae">https://gist.github.com/sscalpone/11f58f248cc2a984be80a6b0867836ae</a><br>
 <br>
macOS<br>
<a href="https://gist.github.com/sscalpone/79434dcdfd8e5d8b568a485329562063">https://gist.github.com/sscalpone/79434dcdfd8e5d8b568a485329562063</a><br>
 <br>
aarch64<br>
<a href="https://gist.github.com/sscalpone/8aaec89cadb27c7ee580c6f460c955f4">https://gist.github.com/sscalpone/8aaec89cadb27c7ee580c6f460c955f4</a><br>
 <br>
 - Steve<br>
<br>
On 4/2/20, 12:11 PM, "flang-dev on behalf of Richard Barton via flang-dev" <flang-dev-bounces@lists.llvm.org on behalf of flang-dev@lists.llvm.org> wrote:<br>
<br>
    Hi flang-dev<br>
<br>
    During the code review on the patch to switch F18's file handling code from using C library to C++ library routines [1] we hit upon a case that seemed to show the C++ std::remove_if routine was much slower than the C routine on some platforms. The routine
 in question is RemoveCarriageReturns in lib/Parser/source.cpp [2] and existing findings are at [3][4][5]. We are seeing quite different performance numbers across different platforms.<br>
<br>
    Peter Klausler made a little performance harness around the two proposed implementations  and a third naïve implementation that we would expect to be the slowest (for reference rather than proposed for use in F18). I have attached this harness, with a few
 NFC modifications to this email.<br>
<br>
    Is anyone able to give this a run on their system and report their results? Please enable optimisation whilst compiling as this will match the F18 configuration we most care about. Please include the compiler and C & C++ standard library versions used as
 well as the architecture and platform. We've not tried this at all on Windows, so we'd be interested if anyone can provide that info.<br>
<br>
    The implementation using std::remove_if is preferred on LLVM-like style grounds so we would like to make this change. However, we don't want to significantly regress the performance of F18 file reading while we do that. We'd like to make the change but
 only if the new code is in the same performance ballpark as the existing code.<br>
<br>
    Thanks<br>
    Rich<br>
<br>
    [1] <a href="https://github.com/flang-compiler/f18/pull/1032">https://github.com/flang-compiler/f18/pull/1032</a><br>
    [2] <a href="https://github.com/flang-compiler/f18/blob/96c6be633ff65ec6d84c18e0d14393137d8097dd/lib/Parser/source.cpp#L73">
https://github.com/flang-compiler/f18/blob/96c6be633ff65ec6d84c18e0d14393137d8097dd/lib/Parser/source.cpp#L73</a><br>
    [3] <a href="https://github.com/flang-compiler/f18/pull/1032#discussion_r391846621">
https://github.com/flang-compiler/f18/pull/1032#discussion_r391846621</a><br>
    [4] <a href="https://github.com/flang-compiler/f18/pull/1032#discussion_r392125932">
https://github.com/flang-compiler/f18/pull/1032#discussion_r392125932</a><br>
    [5] <a href="https://github.com/flang-compiler/f18/pull/1032#discussion_r392311031">
https://github.com/flang-compiler/f18/pull/1032#discussion_r392311031</a><br>
    -----------------------------------------------------------------------------------<br>
    This email message is for the sole use of the intended recipient(s) and may contain<br>
    confidential information.  Any unauthorized review, use, disclosure or distribution<br>
    is prohibited.  If you are not the intended recipient, please contact the sender by<br>
    reply email and destroy all copies of the original message.<br>
    -----------------------------------------------------------------------------------<br>
    _______________________________________________<br>
    flang-dev mailing list<br>
    flang-dev@lists.llvm.org<br>
    <a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/flang-dev">https://lists.llvm.org/cgi-bin/mailman/listinfo/flang-dev</a><br>
<br>
_______________________________________________<br>
flang-dev mailing list<br>
flang-dev@lists.llvm.org<br>
<a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/flang-dev">https://lists.llvm.org/cgi-bin/mailman/listinfo/flang-dev</a><br>
</div>
</span></font></div>
</body>
</html>