home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / comp / lang / pascal / 8629 < prev    next >
Encoding:
Text File  |  1993-01-28  |  3.1 KB  |  116 lines

  1. Newsgroups: comp.lang.pascal
  2. Path: sparky!uunet!ukma!carld
  3. From: carld@ms.uky.edu (Carl Lafferty)
  4. Subject: Multiply vs indexing.
  5. Message-ID: <C1Kw3z.4JG@ms.uky.edu>
  6. Summary: Why does indexing an array seem slower than multiplication.
  7. Keywords: Multiply index graphics
  8. Organization: University Of Kentucky, Dept. of Math Sciences
  9. Date: Thu, 28 Jan 1993 19:14:20 GMT
  10. Lines: 104
  11.  
  12. I have a program that uses the 320x200x256 vga mode quite a bit and I am 
  13. always looking for ways to speed up things.  One of the methods I tried
  14. recently involved creating an array that contains the line beginnings offsets
  15. so that I will not have to multiply my Y value by 320 for each putpixel. {
  16. I am not using putpixel a lot it is just my test of this method}  What happens
  17. is that I seem to be taking more time to index to the array than to
  18. do the multiplication.  Is this because in indexing to the array it must 
  19. multiply the index by the record length anyway or am I doing something stupid.
  20.  
  21. The code is below if anyone is interested enough.
  22.  
  23. ---------------------------Begin code here---------------------------
  24. uses crt,dos;
  25. var
  26.    a : array[0..319] of byte;
  27.  
  28.    linebegin : array[0..199] of word;
  29.  
  30. FUNCTION Time : real;
  31. {
  32.    Get time from system clock, Seconds, and Hundredths of Seconds
  33.    to time in HUNDREDTH of Seconds.    This makes it
  34.    easy to measure elapsed time by subtracting one time from another
  35.    later time.
  36. }
  37.  
  38.  
  39. VAR
  40.   Reg : Registers;
  41.  
  42. BEGIN
  43.   Reg.AX := $2C00;
  44.   Intr($21,Reg);
  45.   Time := (Reg.CX and $00FF) * 60 * 100
  46.         + ((Reg.DX shr 8)*100)     { * 1 }     {Seconds    }
  47.         + (Reg.DX and $00FF)    ;   {Hundredths }
  48. END;
  49.  
  50. Procedure SetMode( Mode : Byte );
  51.  
  52. Begin
  53.     asm
  54.         mov ah, 00h
  55.         mov al, mode
  56.         int 10h
  57.     end
  58. End;
  59.  
  60.  
  61.  
  62.  
  63. Procedure OLDputpixel(x,y : integer; color : byte);
  64. begin
  65.      mem[$A000:(y*320)+x] := color;
  66. end;
  67.  
  68. Procedure Newputpixel(x,y : integer; color : byte);
  69.  
  70. begin
  71.      mem[$A000:linebegin[y] + x] := color;
  72. end;
  73.  
  74. var
  75.    start1,finish1,dif1,start2,finish2,dif2 : real;
  76.    t,r,e : integer;
  77. begin
  78.      setmode($13);  {This just sets the mode to 320x200x256 vga}
  79.      directvideo := false; {So I can write on a graphics screen with
  80.                             no BGI fonts}
  81.  
  82.      {Seed my array with the values}
  83.      for t := 0 to 199 do
  84.          linebegin[t] := t * 320;
  85.  
  86.      start1 := time;
  87.      for e := 1 to 20 do
  88.      for t := 0 to 319 do
  89.          for r := 0 to 199 do
  90.              newputpixel(t,r,10);
  91.      finish1 := time;
  92.  
  93.      dif1 := Finish1 - start1;
  94.      start2 := time;
  95.      for e := 1 to 20 do
  96.      for t := 0 to 319 do
  97.          for r := 0 to 199 do
  98.              oldputpixel(t,r,1);
  99.      Finish2 := time;
  100.  
  101.      dif2 := Finish2 - start2;
  102.  
  103.      writeln('Using the table   ',dif1:10:5);
  104.      writeln('Not using a table ',dif2:10:5);
  105.      readln;
  106.      textmode(co80);
  107. end.
  108. ------------------------------End code----------------------------
  109.  
  110. Any and all comments by whatever means is acceptable.  Just seems to me 
  111. that the array would be faster.  ALso acceptable will be pascal examples
  112. of how to do stuff by the ports on a vga card. 
  113.  
  114. Carl Lafferty    
  115.  
  116.