Author: William Kerr
Date: 09:39:09 05/26/00
Go up one level in this thread
On May 26, 2000 at 10:25:39, blass uri wrote: >I understand that searching for the value of a varaible can take more time if >the variable is not in the CPU(not register variable). > >I have some questions > >1)Is searching for the value of a register variable takes the same time in case >of more variables when there are more variables in the CPU. > For ang given CPU there is a limit of the number of register variables that the compiler will assign. Regardless of how many register variables get used, it take the cpu the same time to find any register variable. >2)Is searching for the value of a variable takes more time in case of more >variables if the variable is not in the CPU. If the compiler can't allocate all register variables then the remaining variables get stored in ram eithor on the heap or on the stack if its a local variable. It takes the cpu the same time to find any heap variable regardless of how many heap variables there are. The cpu knows the absolute address of all heap variables. The same is true of local variables that are stored on the stack. Regardless of how many variables are stored on the stack, the cpu can find any one of them in the same time. The time to find a heap variable may not be the same time to find a stack variable depending on the address mode chosen by the compiler to fetch variables. > >3)How many register variables can be saved in the registers of the CPU Depends on the cpu and the type of variable being stored; 8 bit char, 16 bit integer, 32 bit integer or floating point number. Probably not more than 2 or 3 for Intel processors, though Im guessing here. The compiler has the final say on how many variables will be stored in registers. >4)How much faster is using register variables relative to using not register >variables? Depends on how often the variable is used and how large the routine is that uses that variable. Generally register variables are used in loops where the variables is accessed thousands of times. Best case I'm guessing maybe you'd see 50% increase in a small routine that loops many times, but I suspect you'd only see a few percent increase if lucky in most medium sige routines. > >My logic say that searching for the value of the variable should take more time >in every case when there are more variables because searching for a word in a >big dictionary takes more time than searching for a word in a small dictionary >but I do not know if computers search in a "dictionary" for variables or use >another method. Compiles programs C, C++ etc. the cpu takes the same time to find a variable no matter how many there are (interpreted BASIC programs took longer to find variables the more there were). Sor you can have as many global or local variables you want, the cpu will find each variable of the same type (global, local) in the same length of time. However the cpu may take a smidge longer to find local (stack) variables than global ones. > >I understand that the reply to questions 3 and 4 may be dependent on the >hardware > >Uri Bill
This page took 0 seconds to execute
Last modified: Thu, 15 Apr 21 08:11:13 -0700
Current Computer Chess Club Forums at Talkchess. This site by Sean Mintz.