473,385 Members | 2,162 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Processing an array

542 512MB
The following code is twice as fast using 'max' rather than just 11 in the three loops. Could someone explain why this is so?
Expand|Select|Wrap|Line Numbers
  1. int main()
  2. {
  3.     int const max=11;
  4.     int count=0,num=0;
  5.     int a[]={2,3,5,7,6,1,4,9,8,2,5};
  6.     //print array
  7.     cout<<"\n\n";
  8.     cout<<"the array is: \n";
  9.     for(int i=0;i<max;i++)
  10.     cout<<a[i]<<" ";
  11.     //now find which integers are repeated
  12.     for(int i=0;i<max;i++)
  13.      {
  14.        for(int j=0;j<max;j++)
  15.           {
  16.           if(a[j]==i)
  17.           count++;
  18.           }
  19.         if(count<1)continue;
  20.         if(count>num)num=count;
  21.         cout<<"\nthere was "<<count<<" "<<i;
  22.         count=0;
  23.  
  24.     }
  25.  cout<<"\nthe most repeats was "<<num<<endl;
  26.  
  27. }
thanks in advance
Jun 30 '11 #1
4 1865
Banfa
9,065 Expert Mod 8TB
How did you measure this? Because over an iteration of 11 items I would have thought the difference would either be not measurable or not significant.
Jun 30 '11 #2
whodgson
542 512MB
I have just acquired code::blocks (am not very familiar)and it routinely publishes the execution time for a program although I`m not sure if this includes the screen writing time (hope not). In this case it said either 0.125 s(with 11) or 0.063 s (with max).
Jul 1 '11 #3
Banfa
9,065 Expert Mod 8TB
Well I can't explain it and there seems no reason why is should be different for me.

Compiling and running in Code:Blocks (which I just happen to have installed) gives run times of 0.003s for both cases.
Jul 2 '11 #4
whodgson
542 512MB
OK thanks Banfa. I will look into it further.
Jul 3 '11 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

21
by: Patrick Dunford | last post by:
PHP allows control arrays in forms e.g. this is a counter editing script echo "<input name=\"counterdelname\" type=\"hidden\" value=\""; echo "<input name=\"countername\" type=\"hidden\"...
3
by: jdemello | last post by:
When using a multidimensional associative array to cross-reference data in a second, single-dimensional array, PHP stops processing data after a few iterations. Memory usage according to the task...
23
by: Daniel Rudy | last post by:
Hello, I'm trying to learn how command line arguments are handled in C. The following code segment that I wrote as a test program compiles, but when I try to run it, it core dumps. This is...
0
by: Claire | last post by:
My application has a thread reading byte arrays from an unmanaged dll(realtime controller monitoring). The array represents an unmanaged struct containing a series of header fields plus a variable...
5
by: Geoff Jones | last post by:
Hi Suppose we have an array of DataRows e.g. Dim drMyRows() As DataRow = myTable.Rows(0).GetChildRows("PricesCompany") generated via a relationship. The question I have is this. Isn't...
12
by: jamie | last post by:
I wish to create an array that points to, say, the middle section of a different array. eg Original array > second array-------------^ Is this at all possible?? I think that it...
14
by: rocketman768 | last post by:
Man, that title should be in a poem, but anyways...So, I have this program, and it has an array of 40 million elements. The problem is that I have a for loop that continually is doing stuff to this...
5
by: paul | last post by:
Hi all, Could some kind soul peruse the following code and see if there is anything wrong with it? Its producing output, but its only occupying the first third of the output array; to give an...
1
by: assgar | last post by:
Hi I need help solving a porblem. I have a form that displays a checkbox, service code, description and dropdown with fees on each row. The fee_money and unit array only returns a...
2
by: perlaroha | last post by:
I have an array @arr as: aa bb cc dd ee ff gg hh kk tt yy uu I need to extract the second coulmn from this & push it to another array called @brr so that it contains only bb
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.