Skip to content

Optimize I/O in all test files: sync_with_stdio + cin.tie + endl→"\n" - #16

Merged
blue-jam merged 3 commits into
mainfrom
copilot/optimize-cin-performance
Mar 27, 2026
Merged

Optimize I/O in all test files: sync_with_stdio + cin.tie + endl→"\n"#16
blue-jam merged 3 commits into
mainfrom
copilot/optimize-cin-performance

Conversation

Copilot AI commented Mar 27, 2026

Copy link
Copy Markdown
Contributor

cin-based I/O in test files was unoptimized — C/C++ stream sync and cout flushing on every endl add unnecessary overhead.

Changes

  • All 31 *.test.cpp files: Added at the top of main():
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
  • All 31 *.test.cpp files: Replaced every endl with "\n" to avoid implicit flush on each output.

Before / After

// Before
int main() {
    int n;
    cin >> n;
    cout << n << endl;
}

// After
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin >> n;
    cout << n << "\n";
}
Original prompt

テストコードでcinを使っているファイルがあるけど、入力がボトルネックになっているかもしれない。適切なコード変更を加えて。使うテクニックは

ios_base::sync_with_stdio(false);
cin.tie(NULL);
と、endlのかわりに、"\n"を使うやつ。


📍 Connect Copilot coding agent with Jira, Azure Boards or Linear to delegate work to Copilot in one click without leaving your project management tool.

Copilot AI changed the title [WIP] Optimize cin performance in test code Optimize I/O in all test files: sync_with_stdio + cin.tie + endl→"\n" Mar 27, 2026
Copilot AI requested a review from blue-jam March 27, 2026 09:25
@blue-jam
blue-jam marked this pull request as ready for review March 27, 2026 12:28
@blue-jam
blue-jam merged commit e56e5b2 into main Mar 27, 2026
3 checks passed
@blue-jam
blue-jam deleted the copilot/optimize-cin-performance branch March 27, 2026 23:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants