Skip to content

Removed excessive use of std::endl from examples. #1773

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: dev
Choose a base branch
from

Conversation

Dimi1010
Copy link
Collaborator

Removed excessive use of std::endl in examples.

Each std::endl call flushes the stream in addition to appending a new line ('\n') character if the stream is buffered (std::cout). Usages of it in the middle of a long string block can cause performance overhead where the stream is repeatedly flushed without a need for it.

This PR addresses this issue by replacing calls to std::endl in the middle of string blocks with '\n'. In addition the PR groups adjacent C-string literals, by removing the << operators between them. Under the C++ standard, adjacently declared C-string literals are packed into a single C-string during compilation.

Copy link

codecov bot commented Apr 14, 2025

Codecov Report

Attention: Patch coverage is 36.89320% with 65 lines in your changes missing coverage. Please review.

Project coverage is 83.23%. Comparing base (98d36de) to head (2cf5c95).

Files with missing lines Patch % Lines
Examples/IcmpFileTransfer/Common.cpp 0.00% 14 Missing ⚠️
Examples/DnsSpoofing/main.cpp 0.00% 11 Missing ⚠️
Examples/DNSResolver/main.cpp 18.18% 9 Missing ⚠️
Examples/Arping/main.cpp 0.00% 8 Missing ⚠️
Examples/ArpSpoofing/main.cpp 0.00% 6 Missing ⚠️
Examples/HttpAnalyzer/main.cpp 64.28% 5 Missing ⚠️
...ples/IcmpFileTransfer/IcmpFileTransfer-pitcher.cpp 0.00% 4 Missing ⚠️
Examples/IPDefragUtil/main.cpp 83.33% 3 Missing ⚠️
...ples/IcmpFileTransfer/IcmpFileTransfer-catcher.cpp 0.00% 3 Missing ⚠️
Examples/XdpExample-FilterTraffic/main.cpp 0.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##              dev    #1773      +/-   ##
==========================================
+ Coverage   83.10%   83.23%   +0.12%     
==========================================
  Files         283      283              
  Lines       48929    48777     -152     
  Branches    10294    10518     +224     
==========================================
- Hits        40664    40598      -66     
+ Misses       7126     7040      -86     
  Partials     1139     1139              
Flag Coverage Δ
alpine320 75.09% <45.83%> (+0.01%) ⬆️
fedora40 75.11% <45.83%> (+<0.01%) ⬆️
macos-13 80.74% <38.00%> (+0.13%) ⬆️
macos-14 80.74% <38.00%> (+0.13%) ⬆️
macos-15 80.71% <38.00%> (+0.13%) ⬆️
mingw32 70.73% <ø> (-0.02%) ⬇️
mingw64 70.67% <ø> (-0.04%) ⬇️
npcap 85.05% <ø> (-0.02%) ⬇️
rhel94 74.95% <45.83%> (ø)
ubuntu2004 58.54% <45.83%> (+<0.01%) ⬆️
ubuntu2004-zstd 58.65% <45.83%> (-0.03%) ⬇️
ubuntu2204 74.89% <45.83%> (+0.03%) ⬆️
ubuntu2204-icpx 61.49% <ø> (ø)
ubuntu2404 75.13% <45.83%> (+0.02%) ⬆️
unittest 83.23% <36.89%> (+0.12%) ⬆️
windows-2019 85.08% <ø> (-0.01%) ⬇️
windows-2022 85.10% <ø> (-0.01%) ⬇️
winpcap 85.25% <ø> (ø)
xdp 50.57% <0.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

<< " -g gateway_ip : The IPv4 address of the gateway" << std::endl
<< " -h : Displays this help message and exits" << std::endl
<< " -v : Displays the current version and exists" << std::endl
std::cout << "\nUsage:"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the strings like here, the performace doesn't matter actually. Personally, I prefer the original std::endl which looks clearer.

Copy link
Collaborator Author

@Dimi1010 Dimi1010 Apr 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I find the '\n' version significantly cleaner to read and visualize how the string will be formatted on the console. Especially for places where clang-format places the << std::endl on the next line.

@tigercosmos
Copy link
Collaborator

I looked over the PR. It seems that there is no permance intensive code that std::endl can slow down the performance. Most of the cases are just printing the info or usages. I would suggest keeping the original code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants