2013年11月14日星期四

Alibaba 2014 pen test , speed to the crowd ! ! !

Q. Which of the following method is faster


public class FFFtest {
public static void main(String[] args) {
int[] a=new int[1000];
int[] b=new int[10000000];
long start = System.currentTimeMillis();
//method 1
for(int i=0;i<1000;i++){
for(int j=0;j<10000000;j++){
a[i]++;
}
}
long end = System.currentTimeMillis();
System.out.println(end-start);

start=System.currentTimeMillis();
//method 2
for(int i=0 ;i<10000000;i++){
for(int j=0;j<1000;j++){
b[i]++;
}
}
end = System.currentTimeMillis();
System.out.println(end-start);


}
}

Output:
25616
21736

The results indicated that the second in faster, demand an explanation ! ! !
------ Solution ---------------------------------------- ----
test 1: the assignment statement notes
 public static void main(String[] args) {
        int[] a=new int[1000];
        int[] b=new int[10000000];
        long start = System.currentTimeMillis();
        //method 1
        for(int i=0;i<1000;i++){
            for(int j=0;j<10000000;j++){
//                a[i]++;
            }
        }
        long end = System.currentTimeMillis();
        System.out.print(end-start+"\t");
         
        start=System.currentTimeMillis();
        //method 2
        for(int i=0 ;i<10000000;i++){
            for(int j=0;j<1000;j++){
//                b[i]++;
            }
        }
        end = System.currentTimeMillis();
        System.out.println(end-start);

    }

Test Results:
3704 4095
3625 3860
3609 3877
3609 4001


Test 2 : Restore the assignment ( same landlord code )
Test Results:
23616 22096
23048 21986
24164 22495
23532 22175

Results Analysis:
1, by testing one ( only cycle through consuming ) can prove the 6th floor of said first code cut from the inner to the outer loop number is 1000 ; second code from the inside cut to the outer layer of the number of cycles is 10 million times, so much more time-consuming switching

2, with the assignment by testing two saw the first code after consuming significantly increased significantly, the number two codes are the same assignment , but the first piece of code from each array element is 1-10000000 assignment big big data storage assignment

So I think the whole big assignment will be more time-consuming large data
------ Solution --------------------- -----------------------
this theme rational knowledge should be the first one is faster.
because a [i] and b [i] is a memory lookup action, and a [i] find only 1000 times , b [i] was searched 10,000,000 times. a [i] more hit the CPU cache ( fast ) , and b [i] for more memory lookup ( slow ) .

Ever since this is a micro benchmark problem. Java- micro benchmark is difficult, there is no absolutely fair way . Difficulty lies in the JVM JIT.

The method for micro benchmark , we must first be preheated , and secondly to statistics.
Preheat concept is to let the JVM first run the method several times ( Keywords : compile threshold), so that the JIT compiler optimization methods .
statistical mean is running several tests , take the average , median , standard deviation, a comprehensive comparison of data .
Another point to note is that absolutely can not be tested in the same program there are two ways . To compile test different versions of the two methods were tested , or there will be interference.

The following is my test method: The test which I did not use statistical methods , because the result is already clear : the way a method of two than about 2.5 times faster

package test;

public class Test {

  static int[] a = new int[100];
  static int[] b = new int[100000];

  public static void main(final String[] args) throws Exception {

    // warm up
    for (int i = 0; i < 5000; i++)
      method2();

    long start = System.currentTimeMillis();
    for (int i = 0; i < 1000; i++)
      method2();
    long end = System.currentTimeMillis();
    System.out.println(end - start);
  }

  static void method1() {
    for (int i = 0; i < 100; i++) {
      for (int j = 0; j < 100000; j++) {
        a[i]++;
      }
    }
  }

  static void method2() {
    for (int i = 0; i < 100000; i++) {
      for (int j = 0; j < 100; j++) {
        b[i]++;
      }
    }
  }
}


This is the method of two test code, you want a measuring method , just put inside the main change method1 method2

------ For reference only ---------------------------------- -----
personal feeling for the number of cycles a second less so fast

------ For reference only ---------------------------------- -----
two methods of calculating the total number is the same , but the loop nest different. Arguably should spend the same time thing
------ For reference only ------------------------------ ---------
Wait experts come out to tell you your test methods unscientific
------ For reference only -------------------------- -------------
What is ancient machine ah
I tested out the second generation i5-2410
478
728

Then all of my 10 million more a 0 , drawn
4749
7190

you do not know what wonderful machine , may not the same optimization
I think the focus should be on the inside for loop variable declaration issues ,
first cycle i declare a second , j1000 times
second i1 times , j10000000 times
old Shichiku big blog for reference. .
http://blog.csdn.net/java2000_net/article/details/4314894

Please indicate where I do not talk . .
------ For reference only -------------------------------------- -

variable declaration does affect the calculation of the number of times that I put variables are declared to be outside the loop , then the for loop , why small cycles faster sets a cycle calculation

------ For reference only ---------------------------------- -----
loop nest , then toggle between cycles ( such as the first loop jump into the second loop ) need to consume some time .
If large circle on the inside of the switch between cycles to spend a little less time , so the large loop on the inside is less time-consuming , higher efficiency .
------ For reference only -------------------------------------- -
you read that blog yet , different machines computation time differently.
This gap should be very small of it, personally see no need to tangle this
------ For reference only ------------------ ---------------------
I was so considered , so I was also a large selection of small sets of high cycle efficiency .
------ For reference only -------------------------------------- -

Alibaba yesterday to do written tests, there is such a problem ! ! !

------ For reference only ---------------------------------- -----
well -question , we can do it without watching :
int a = 1;
int b = 2;
without using temporary variable in the case with the three lines of code switching a, b ​​values.
------ For reference only -------------------------------------- -

public class sdfsd {
public static void main(String[] args){
int a=1;
int b=3;
a=a^b;
b=b^a;
a=a^b;
System.out.println(b);
System.out.println(a);
}
}
personally think that this is just skill Bale
------ For reference only ------------------------- --------------

int a = 1;
int b = 2;
a ^ = b;
b ^ = a;
a ^ = b;
System.out.print (a);
System.out.print (b);
------ For reference only --------- ------------------------------
remove the initialization of this factor , the running time is very short , and the gap is small , individuals do not It will cause a performance bottleneck , I do not tangle up , waiting for the master
------ For reference only ---------------------------------------
analysis is in place, I am more agree with your point of view , large data storage time-consuming and more large , circular toggle also have differences .
In addition, 4th Floor, variable declaration mentioned also a number of reasons .
summarized below:
1, the number of variable declarations : method 1 where i declare a second , j declares 1000 , method 2 , i is declared 1 , j declares 10000000 ;
2, Cycle : the inner loop and outer loop switching frequency , method 1 is 1000 , method 2 was 10 million times ;
3, Data storage : method 2 in the inner loop accumulate 10 million times, data is very large, while method 2 only accumulated 1000 times ;

11 shows the floor of the test separately consider the first three factors , a large set of small circulation faster than the small set of large , because the data is relatively small, the storage efficiency. However, consider three factors integrated in the data in size, variable declaration only used once , the loop switching time will be more critical .
written yesterday when got nothing to think we chose a small set of large , I think he should consider switching cycle is time-consuming .
I do not know whether it is appropriate to say , please correct me
------ For reference only ------------------------- --------------
int a = 1, b = 2;
a = a + b; / / a = 3 b = 2
b = a-b; / / a = 3 b = 1
a = a-b; / / a = 2 b = 1

------ For reference only ---------------------------------- -----

this method a little bit of a problem , is the fear of a + b , and exceeds the maximum int
------ For reference only ------- --------------------------------


old-fashioned title
------ For reference only ------------------------------- --------

this method a little bit of a problem , is the fear of a + b , and exceeds the maximum int  

just ask JAVA type of data which is " a positive integer " in
replace the int is not a positive integer overflows do not be afraid to swap the overflow 2 times

------ For reference only ---------------------------------- -----
that I attended last night ali written estimated LZ region , like me, have news yet ?
I chose this topic is t2 fast, perceptual and 11L coincide . . .
Khan , which means a lot of pressure ah. . .
------ For reference only -------------------------------------- -

this method a little bit of a problem , is the fear of a + b , and exceeds the maximum int  

int a = int.MaxValue;
            int b = int.MaxValue - 1;
            Console.WriteLine("a={0};b={1}", a, b);
            a = a + b;
            b = a - b;
            a = a - b;
            Console.WriteLine("a={0};b={1}", a, b);

test results , a, b indeed exchanged
------ For reference only ------------------------ ---------------
upstairs solution ,
------ For reference only -------------- -------------------------
such code , almost fast.

principle is a small loop on the outside is good , the first one .
------ For reference only -------------------------------------- -
I think we should follow the instruction pipeline to establish a relationship ( he considered to be three lines ) .
------ For reference only -------------------------------------- -
is because the memory pages of the switch, the inner and outer loop times vary greatly, the order would result in unreasonable unreasonable memory paging , kept swapped in and out affect the efficiency
--- --- For reference only ---------------------------------------
variables local variables stored in the stack , there should be a push and pop influence .
------ For reference only -------------------------------------- -

this method a little bit of a problem , is the fear of a + b , and exceeds the maximum int          
  
  
int a = int.MaxValue;
            int b = int.MaxValue - 1;
            Console.WriteLine("a={0};b={1}", a, b);
            a = a + b;
            b = a - b;
            a = a - b;
            Console.WriteLine("a={0};b={1}", a, b);
  
test results , a, b does exchanged  
just tested a bit , too, I began to take it for granted , thank correction.
------ For reference only -------------------------------------- -

your test methods unscientific . Do not believe you put method1 and method2 change my position to try
------ For reference only --------------------------- ------------
Hangzhou , candidates are R & D engineers , completely wooden news is not reported any expectation ...
------ For reference only - -------------------------------------
can reveal a little more what title
------ For reference only ---------------------------------------

your test unscientific . Do not believe you put method1 and method2 try to change my position   seems to be somewhat unscientific .. how to change , there is wood there a way ?
------ For reference only ------------------ ---------------------

a = a + b;
b = a-b;
a = ab;
------ For reference only ---------------------------- -----------
exchange data without third-party
so old-fashioned title
Zhennai Classic interview questions
------ For reference only ----------------------------- ----------
very interesting cycle efficiency.
------ For reference only -------------------------------------- -
your opinions are very pertinent to the future will be more attention test
------ For reference only ---------------------------------------
in C + + , in general method 2 of the CPU CACHE hit rate than method 1.
inference test sites is this one.
------ For reference only -------------------------------------- -
why do I feel about it and this is the cache
------ For reference only ---------------------------------------
layers for large data to be Note that the number of inner loop not large than the outer layer , this is very time-consuming

small data cycle can be useless note
------ For reference only -------------------------- -------------



Really
------ For reference only ------------------------------- --------


a ^ = b
b ^ = a
a ^ = b
------ For reference only ------------------------------ ---------
not use the third method of variables :
int a;
int b;
a = a + b;
b = a - b;
a = a - b;
------ For reference only ---------------------- -----------------
What rubbish title , Ali this really is a question for the level of bad people .
java is running in a virtual machine , this hardware dependence, virtual machine -dependent title does not make sense .

------ For reference only ---------------------------------- -----
theory, loop less on the outside, and more on the inside.
------ For reference only -------------------------------------- -


a = a + b;
b = a-b;
a = a-b;


------ For reference only ---------------------------------- -----
there's no tomorrow to Ali interview ah. Chant together . 3:00 halftime .
------ For reference only -------------------------------------- -
analysis is in place, I am inclined to agree with your point of view , large data storage time-consuming and more large , circular toggle also have differences .   
In addition, 4th Floor, variable declaration mentioned also a number of reasons .   
summarized below:   
1, the number of variable declarations : method 1 where i declare a second , j declares 1000 , method 2 , i is declared 1 , j declares 10000000 ;   
2, Cycle : the inner loop and outer loop switching frequency , method 1 is 1000 , method 2 was 10 million times ;   
3, Data storage : method 2 in the inner loop accumulate 10 million times, data is very large, while method 2 only accumulated 1000 times ;   
  
11 shows the floor of the test separately consider the first three factors , a large set of small circulation faster than the small set of large , because the data is relatively small, the storage efficiency. However, consider three factors integrated in the data in size, variable declaration only used once , the loop switching time will be more critical .   
written yesterday when got nothing to think we chose a small set of large , I think he should consider switching cycle is time-consuming .   
I do not know whether it is appropriate to say , please correct me  
still feel this more reliable !
------ For reference only -------------------------------------- -
the way, how Alibaba screening resumes , ah ? Pa did not pass the pen is not allowed ?
------ For reference only -------------------------------------- -
analysis is in place, I am inclined to agree with your point of view , large data storage time-consuming and more large , circular toggle also have differences .     
In addition, 4th Floor, variable declaration mentioned also a number of reasons .     
summarized below:     
1, the number of variable declarations : method 1 where i declare a second , j declares 1000 , method 2 , i is declared 1 , j declares 10000000 ;     
2, Cycle : the inner loop and outer loop switching frequency , method 1 is 1000 , method 2 was 10 million times ;     
3, Data storage : method 2 in the inner loop accumulate 10 million times, data is very large, while method 2 only accumulated 1000 times ;     
    
11 shows the floor of the test separately consider the first three factors , a large set of small circulation faster than the small set of large , because the data is relatively small, the storage efficiency. However, consider three factors integrated in the data in size, variable declaration only used once , the loop switching time will be more critical .     
written yesterday when got nothing to think we chose a small set of large , I think he should consider switching cycle is time-consuming .     
I do not know whether it is appropriate to say , please correct me          
still feel this more reliable !  
nonsense
------ For reference only -------------------------------- -------
analysis is in place, I am inclined to agree with your point of view , large data storage time-consuming and more large , circular toggle also have differences .       
In addition, 4th Floor, variable declaration mentioned also a number of reasons .       
summarized below:       
1, the number of variable declarations : method 1 where i declare a second , j declares 1000 , method 2 , i is declared 1 , j declares 10000000 ;       
2, Cycle : the inner loop and outer loop switching frequency , method 1 is 1000 , method 2 was 10 million times ;       
3, Data storage : method 2 in the inner loop accumulate 10 million times, data is very large, while method 2 only accumulated 1000 times ;       
      
11 shows the floor of the test separately consider the first three factors , a large set of small circulation faster than the small set of large , because the data is relatively small, the storage efficiency. However, consider three factors integrated in the data in size, variable declaration only used once , the loop switching time will be more critical .       
written yesterday when got nothing to think we chose a small set of large , I think he should consider switching cycle is time-consuming .       
I do not know whether it is appropriate to say , please correct me                
still feel this more reliable !          
nonsense  
Can you talk about your views
------ For reference only --------------------------- ------------
analysis is in place, I am inclined to agree with your point of view , large data storage time-consuming and more large , circular toggle also have differences .         
In addition, 4th Floor, variable declaration mentioned also a number of reasons .         
summarized below:         
1, the number of variable declarations : method 1 where i declare a second , j declares 1000 , method 2 , i is declared 1 , j declares 10000000 ;         
2, Cycle : the inner loop and outer loop switching frequency , method 1 is 1000 , method 2 was 10 million times ;         
3, Data storage : method 2 in the inner loop accumulate 10 million times, data is very large, while method 2 only accumulated 1000 times ;         
        
11 shows the floor of the test separately consider the first three factors , a large set of small circulation faster than the small set of large , because the data is relatively small, the storage efficiency. However, consider three factors integrated in the data in size, variable declaration only used once , the loop switching time will be more critical .         
written yesterday when got nothing to think we chose a small set of large , I think he should consider switching cycle is time-consuming .         
I do not know whether it is appropriate to say , please correct me                      
still feel this more reliable !                
nonsense          
Can you talk about your views  
33 F
------ For reference only -------------------------------- -------
tested repeatedly , whether or not circulating inside a [i] + + , etc., two broadly similar test time . Separation test results the same.
In addition to my machine is a dual-core 2.5G XP32 three generations I5 system . The test of time and lz less, I do not know so little upstairs test time is how to do.
------ For reference only -------------------------------------- -
b = (a + b) - (a = b);
------ For reference only -------------------- -------------------

this method a little bit of a problem , is the fear of a + b , and exceeds the maximum int          
  
  
int a = int.MaxValue;
            int b = int.MaxValue - 1;
            Console.WriteLine("a={0};b={1}", a, b);
            a = a + b;
            b = a - b;
            a = a - b;
            Console.WriteLine("a={0};b={1}", a, b);
  
test results , a, b does exchanged  

This approach is problematic , at a = a + b; when there is a problem !
------ For reference only -------------------------------------- -


In fact , it may not be nonsense.
For the CPU cache hit , the key is a localized !
Obviously, nested loops into account temporal locality ! The same procedure multiple times with an intensive visit to the region , of course, faster !
So, upstairs comrades have been saying time and it is not unreasonable !

But, correct computational efficiency , which is certainly not the way . Nonsense , I feel wrong !

I do not know what are your opinions , hope the exhibitions !
------ For reference only -------------------------------------- -

  
In fact , it may not be nonsense.   
For the CPU cache hit , the key is a localized !   
Obviously, nested loops into account temporal locality ! The same procedure multiple times with an intensive visit to the region , of course, faster !   
So, upstairs comrades have been saying time and it is not unreasonable !   
  
But, correct computational efficiency , which is certainly not the way . Nonsense , I feel wrong !   
  
I do not know what are your opinions , hope the exhibitions !  
I have really nothing opinions , advice is do not deserve to .
I admit that " nonsense " a bit arrogant , but I did not exaggerating .
1. Variables declared with the number of CPU execution time does not have any relationship with the more efficient the JVM is no relationship between them. Just above a heap variable word length data , declare variables programming language for the convenience of the programmer is to increase readability , the CPU view, " variable" just tell the CPU should be from the heap what position it will be read into the register
2. cycle through different order just code execution , CPU eyes no loops , only similar to the "goto" statement . Of course it needs to execute a statement before the statement is fetched from memory , but these small cycles in a modern CPU , it can be seen all cache hits . If not all the hits , the most frequently executed statement is preserved. From an overall perspective, but all statements are more method2 was "often" to perform , while the outer loop method1 compared to the inner layer is not so "often"
3. data size with the execution time does not matter. Each time plus one just change a few " transistor " with electricity , hardware, do not know your data is large or small , an add operation is one of several clock cycles are almost fixed. Of course, there will be a slight difference, but now you are still 9999999 0 +1 +1 really have nothing

These are some assumptions compiled to native code , directly executed by the CPU of the language . For more JVM on a layer of complexity that I talked about in the 33 floor also need to " warm up " so that the JVM will execute the code compiled to native code , and then undertake benchmark, in order to measure the real efficiency
------ For reference only ---------------------------------------
I still feel and cpu cache hit rates.
1 when the outer loop < && no assignment within the loop , the outer loop number of small, can reduce the cycle jump miss, is to improve instruction forecasting and pipeline efficiency , you can roughly think no inner loop jumps miss, the inner loop will be cut to the outer loop jump miss. Therefore, in the absence of the assignment operator when the outer loop miss 1M number must be better than 1K of the outer loop miss more often .
2 when the outer loop < && inner loop when there is an assignment , that is the case the LZ , since the assignment of particular , when there is a difference with a 1 . Since the array size of about 1M , the current mainstream cpu of a cache is not up to this size , it will inevitably lead to cache and frequent exchange of data between memory and reduce cpu cache hit rate .
But the java virtual machine is how to operate these specific is unknown , but the current jvm efficiency is very high, so it should also make full use of cpu resources .
------ For reference only -------------------------------------- -


support the use of
a = a ^ b;
b = a ^ b;
a = a ^ b;
------ For reference only -------------------- -------------------

    
In fact , it may not be nonsense.     
For the CPU cache hit , the key is a localized !     
Obviously, nested loops into account temporal locality ! The same procedure multiple times with an intensive visit to the region , of course, faster !     
So, upstairs comrades have been saying time and it is not unreasonable !     
    
But, correct computational efficiency , which is certainly not the way . Nonsense , I feel wrong !     
    
I do not know what are your opinions , hope the exhibitions !          
I have really nothing opinions , advice is do not deserve to .   
I admit that " nonsense " a bit arrogant , but I did not exaggerating .   
1. Variables declared with the number of CPU execution time does not have any relationship with the more efficient the JVM is no relationship between them. Just above a heap variable word length data , declare variables programming language for the convenience of the programmer is to increase readability , the CPU view, " variable" just tell the CPU should be from the heap what position it will be read into the register   
2. cycle through different order just code execution , CPU eyes no loops , only similar to the "goto" statement . Of course it needs to execute a statement before the statement is fetched from memory , but these small cycles in a modern CPU , it can be seen all cache hits . If not all the hits , the most frequently executed statement is preserved. From an overall perspective, but all statements are more method2 was "often" to perform , while the outer loop method1 compared to the inner layer is not so "often"   
3. data size with the execution time does not matter. Each time plus one just change a few " transistor " with electricity , hardware, do not know your data is large or small , an add operation is one of several clock cycles are almost fixed. Of course, there will be a slight difference, but now you are still 9999999 0 +1 +1 really have nothing   
  
These are some assumptions compiled to native code , directly executed by the CPU of the language . For more JVM on a layer of complexity that I talked about in the 33 floor also need to " warm up " so that the JVM will execute the code compiled to native code , and then undertake benchmark, in order to measure the real efficiency   listen to Jun 's words, better degree of ten books . . .
------ For reference only -------------------------------------- -

  
support the use of   
a = a ^ b;   
b = a ^ b;   
a = a ^ b;   This method does not appear overflow problem , it should be considered a relatively good
------ For reference only ------------------ ---------------------
  The reply deleted by an administrator at 2013-09-25 13:57:52

------ For reference only ---------------------------------- -----

    
In fact , it may not be nonsense.     
For the CPU cache hit , the key is a localized !     
Obviously, nested loops into account temporal locality ! The same procedure multiple times with an intensive visit to the region , of course, faster !     
So, upstairs comrades have been saying time and it is not unreasonable !     
    
But, correct computational efficiency , which is certainly not the way . Nonsense , I feel wrong !     
    
I do not know what are your opinions , hope the exhibitions !          
I have really nothing opinions , advice is do not deserve to .   
I admit that " nonsense " a bit arrogant , but I did not exaggerating .   
1. Variables declared with the number of CPU execution time does not have any relationship with the more efficient the JVM is no relationship between them. Just above a heap variable word length data , declare variables programming language for the convenience of the programmer is to increase readability , the CPU view, " variable" just tell the CPU should be from the heap what position it will be read into the register   
2. cycle through different order just code execution , CPU eyes no loops , only similar to the "goto" statement . Of course it needs to execute a statement before the statement is fetched from memory , but these small cycles in a modern CPU , it can be seen all cache hits . If not all the hits , the most frequently executed statement is preserved. From an overall perspective, but all statements are more method2 was "often" to perform , while the outer loop method1 compared to the inner layer is not so "often"   
3. data size with the execution time does not matter. Each time plus one just change a few " transistor " with electricity , hardware, do not know your data is large or small , an add operation is one of several clock cycles are almost fixed. Of course, there will be a slight difference, but now you are still 9999999 0 +1 +1 really have nothing   
  
These are some assumptions compiled to native code , directly executed by the CPU of the language . For more JVM on a layer of complexity that I talked about in the 33 floor also need to " warm up " so that the JVM will execute the code compiled to native code , and then undertake benchmark, in order to measure the real efficiency  

This is the standard answer it
------ For reference only ----------------------------- ----------
personally feel that the time spent in that assignment and comparison operations , the statement is done at compile time .
method1 i assignment Compare 1000 1000 i j j assignment Compare 1000000 * 1000000 * 1000 1000 a [i] assignment 1000 1000000 *
method2 i assign relatively 1000000 1000000 times i times j j assignment 1000000 * 1000 * 1000 comparative 1000000 b [i] assignment 1000 1000000 *
So comparing the total number of method1 fast
------ For reference only ------------------------- --------------
learn , a good title
------ For reference only --------------- ------------------------
learn, well, not previously noted
------ For reference only --- ------------------------------------

you are school trick ? Or direct investment resume ah ? Can under the exchange ? Thank you.
------ For reference only -------------------------------------- -

a = a + b;
b = a-b;
a = ab;
------ For reference only ------------------------------ ---------

      
In fact , it may not be nonsense.       
For the CPU cache hit , the key is a localized !       
Obviously, nested loops into account temporal locality ! The same procedure multiple times with an intensive visit to the region , of course, faster !       
So, upstairs comrades have been saying time and it is not unreasonable !       
      
But, correct computational efficiency , which is certainly not the way . Nonsense , I feel wrong !       
      
I do not know what are your opinions , hope the exhibitions !                
I have really nothing opinions , advice is do not deserve to .     
I admit that " nonsense " a bit arrogant , but I did not exaggerating .     
1. Variables declared with the number of CPU execution time does not have any relationship with the more efficient the JVM is no relationship between them. Just above a heap variable word length data , declare variables programming language for the convenience of the programmer is to increase readability , the CPU view, " variable" just tell the CPU should be from the heap what position it will be read into the register     
2. cycle through different order just code execution , CPU eyes no loops , only similar to the "goto" statement . Of course it needs to execute a statement before the statement is fetched from memory , but these small cycles in a modern CPU , it can be seen all cache hits . If not all the hits , the most frequently executed statement is preserved. From an overall perspective, but all statements are more method2 was "often" to perform , while the outer loop method1 compared to the inner layer is not so "often"     
3. data size with the execution time does not matter. Each time plus one just change a few " transistor " with electricity , hardware, do not know your data is large or small , an add operation is one of several clock cycles are almost fixed. Of course, there will be a slight difference, but now you are still 9999999 0 +1 +1 really have nothing     
    
These are some assumptions compiled to native code , directly executed by the CPU of the language . For more JVM on a layer of complexity that I talked about in the 33 floor also need to " warm up " so that the JVM will execute the code compiled to native code , and then undertake benchmark, in order to measure the real efficiency        listen to Jun 's words, better degree of ten books . . .  
teachable teachable
------ For reference only ------------------------------ ---------


10000000 times ~ ~
------ For reference only ------------------------------ ---------
positive solution
------ For reference only ------------------------- --------------
two questions , why must use an array to + + + + variables can not do with another ? Large array length , finding not a waste of time ?
The other is , why the previous method declares the start and end, but the back is a variable declared in front of it ? Why not re- declare variables?
compare to find the only factor that can be more accurate analysis !
------ For reference only ---------------------------------------

you are school trick ? Or direct investment resume ah ? Can under the exchange ? Thank you.  

school trick . But the first round had been washed up .
------ For reference only -------------------------------------- -

you are school trick ? Or direct investment resume ah ? Can under the exchange ? Thank you.          
    
------ For reference only -------------------------------------- -


  
       


------ For reference only -------------------------------------- -
  
    
                         
        
           
                                       
              
              Not quite understand   Thank you.                
                
Thank you.                      
                                
  
    
------ For reference only -------------------------------------- -

        
                                                     
                    
                      Not quite understand                       
                                                                   
                          
                              Not quite understand                          Thank you.                            
                                              
    
                 Thank you.                                  
                                                            
      
                                   Thank you.                                        
                                                                          
        
                                                          
Thank you.                                              
                                                                                        
          
                                                                                      
    

没有评论:

发表评论