×

# Why Such difference in Execution Time?

 0 Execution Time increases by 0.96 secs just because I replaced the data type of a variable from "long long int" to "int" . I was wondering why this happens ? Please Note ( long long takes lesser time than just int ; this is what i found weird) Solutions 1) https://www.codechef.com/viewsolution/21700485 (used long long here)  2) https://www.codechef.com/viewsolution/21700483 (used just int here)  asked 25 Nov '18, 17:24 19●5 accept rate: 0%

 1 Execution time is not increased by data type, it is just because of endl endl flush the cache or buffer whenever it executes, that is why it increases the execution of your solution answered 25 Nov '18, 17:56 5★admin5 226●9 accept rate: 18% Oh thanks ! @admin5 so using "\n" doesn't do the same? (25 Nov '18, 18:00) 1 Yeah! because \n just print the next line nothing else (25 Nov '18, 18:10) admin55★
 0 For what its worth, this code is definitely faster: #include using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int t, n; cin>>t; vector a(1000001, 0); for(int i=0; i> n; ++a[n]; } for(int i=0; i<=1000000; ++i) { for(int j=0; j
 0 sizeof(int) is 16 bits(minimum possible in C language) where as long int is 32 bits and long long int is 64 bit here the space required for the execution of the code will increase exponentially(ie 2^n). Since the space required has increased, =>more data has to be carried in between RAM and processor, =>since finite bits of data can be transferred per cycle from ram to processor => more cycles, (varies from processor to processor) =>each cycle has some execution time. Hence, the increase in execution time. answered 25 Nov '18, 17:39 1 accept rate: 0% Sorry Dude Rather the one with Long Long Is getting executed Earlier ! (25 Nov '18, 17:40) 2 sizeof(int) is 16 bits(minimum possible in C language) where as long int is 32 bits int and long int have same size on codechef. 32 bits. (25 Nov '18, 18:40)
 toggle preview community wiki:
Preview

By Email:

Markdown Basics

• *italic* or _italic_
• **bold** or __bold__
• image?![alt text](/path/img.jpg "title")
• numbered list: 1. Foo 2. Bar
• to add a line break simply add two spaces to where you would like the new line to be.
• basic HTML tags are also supported
• mathemetical formulas in Latex between \$ symbol

Question tags:

×1,901
×74
×21
×20

question asked: 25 Nov '18, 17:24

question was seen: 168 times

last updated: 25 Nov '18, 18:40