Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Is it more efficient to declare variables late?
- int x;
- code
- ..
- .
- .
- . x is able to be used in all this code
- .
- actually used here
- .
- end
- code
- ..
- .
- .
- .
- int x;
- actually used here
- .
- end
- #include <iostream>
- int main() {
- for (int j = 0; j < 1000; ++j) {
- std::cout << j << std::endl;
- }
- int i = 999;
- std::cout << i << std::endl;
- }
- #include <iostream>
- int main() {
- int i = 999;
- for (int j = 0; j < 1000; ++j) {
- std::cout << j << std::endl;
- }
- std::cout << i << std::endl;
- }
- g++ -Wall -Wextra -O4 -S measure.c
- g++ -Wall -Wextra -O4 -S measure2.c
- < .file "measure2.cc"
- ---
- > .file "measure.cc"
- #include <iostream>
- namespace {
- struct foo {
- foo() { }
- ~foo() { }
- };
- }
- std::ostream& operator<<(std::ostream& out, const foo&) {
- return out << "foo";
- }
- int main() {
- for (int j = 0; j < 1000; ++j) {
- std::cout << j << std::endl;
- }
- foo i;
- std::cout << i << std::endl;
- }
- #include <iostream>
- namespace {
- struct foo {
- foo() { }
- ~foo() { }
- };
- }
- std::ostream& operator<<(std::ostream& out, const foo&) {
- return out << "foo";
- }
- int main() {
- foo i;
- for (int j = 0; j < 1000; ++j) {
- std::cout << j << std::endl;
- }
- std::cout << i << std::endl;
- }
Add Comment
Please, Sign In to add comment