home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.pascal
- Path: sparky!uunet!ukma!carld
- From: carld@ms.uky.edu (Carl Lafferty)
- Subject: Multiply vs indexing.
- Message-ID: <C1Kw3z.4JG@ms.uky.edu>
- Summary: Why does indexing an array seem slower than multiplication.
- Keywords: Multiply index graphics
- Organization: University Of Kentucky, Dept. of Math Sciences
- Date: Thu, 28 Jan 1993 19:14:20 GMT
- Lines: 104
-
- I have a program that uses the 320x200x256 vga mode quite a bit and I am
- always looking for ways to speed up things. One of the methods I tried
- recently involved creating an array that contains the line beginnings offsets
- so that I will not have to multiply my Y value by 320 for each putpixel. {
- I am not using putpixel a lot it is just my test of this method} What happens
- is that I seem to be taking more time to index to the array than to
- do the multiplication. Is this because in indexing to the array it must
- multiply the index by the record length anyway or am I doing something stupid.
-
- The code is below if anyone is interested enough.
-
- ---------------------------Begin code here---------------------------
- uses crt,dos;
- var
- a : array[0..319] of byte;
-
- linebegin : array[0..199] of word;
-
- FUNCTION Time : real;
- {
- Get time from system clock, Seconds, and Hundredths of Seconds
- to time in HUNDREDTH of Seconds. This makes it
- easy to measure elapsed time by subtracting one time from another
- later time.
- }
-
-
- VAR
- Reg : Registers;
-
- BEGIN
- Reg.AX := $2C00;
- Intr($21,Reg);
- Time := (Reg.CX and $00FF) * 60 * 100
- + ((Reg.DX shr 8)*100) { * 1 } {Seconds }
- + (Reg.DX and $00FF) ; {Hundredths }
- END;
-
- Procedure SetMode( Mode : Byte );
-
- Begin
- asm
- mov ah, 00h
- mov al, mode
- int 10h
- end
- End;
-
-
-
-
- Procedure OLDputpixel(x,y : integer; color : byte);
- begin
- mem[$A000:(y*320)+x] := color;
- end;
-
- Procedure Newputpixel(x,y : integer; color : byte);
-
- begin
- mem[$A000:linebegin[y] + x] := color;
- end;
-
- var
- start1,finish1,dif1,start2,finish2,dif2 : real;
- t,r,e : integer;
- begin
- setmode($13); {This just sets the mode to 320x200x256 vga}
- directvideo := false; {So I can write on a graphics screen with
- no BGI fonts}
-
- {Seed my array with the values}
- for t := 0 to 199 do
- linebegin[t] := t * 320;
-
- start1 := time;
- for e := 1 to 20 do
- for t := 0 to 319 do
- for r := 0 to 199 do
- newputpixel(t,r,10);
- finish1 := time;
-
- dif1 := Finish1 - start1;
- start2 := time;
- for e := 1 to 20 do
- for t := 0 to 319 do
- for r := 0 to 199 do
- oldputpixel(t,r,1);
- Finish2 := time;
-
- dif2 := Finish2 - start2;
-
- writeln('Using the table ',dif1:10:5);
- writeln('Not using a table ',dif2:10:5);
- readln;
- textmode(co80);
- end.
- ------------------------------End code----------------------------
-
- Any and all comments by whatever means is acceptable. Just seems to me
- that the array would be faster. ALso acceptable will be pascal examples
- of how to do stuff by the ports on a vga card.
-
- Carl Lafferty
-
-