home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 7 / FreshFishVol7.bin / bbs / gnu / libg++-2.6-fsf.lha / libg++-2.6 / libg++ / etc / HINTS < prev    next >
Text File  |  1991-06-28  |  24KB  |  668 lines

  1. BABYL OPTIONS:
  2. Version: 5
  3. Labels:
  4. Note:   This is the header of an rmail file.
  5. Note:   If you are seeing it in rmail,
  6. Note:    it means the file has no messages in it.
  7. 
  8. 1,,
  9. Return-Path: <riedl@cs.purdue.edu>
  10. Received: from oswego.Oswego.EDU by g.oswego.edu (4.0/SMI-4.0)
  11.     id AA08377; Sun, 11 Feb 90 21:33:40 EST
  12. Received: by oswego.Oswego.EDU (5.57/Osw4.1.21)
  13.     id AA00896; Sun, 11 Feb 90 21:33:18 EST
  14. Received: from raid8.cs.purdue.edu by arthur.cs.purdue.edu (5.61/PURDUE_CS-1.2)
  15.     id <AA01233@arthur.cs.purdue.edu>; Sun, 11 Feb 90 21:30:14 -0500
  16. Received: from localhost by raid8.cs.purdue.edu (5.61/PURDUE_CS-1.2)
  17.     id <AA19140@raid8.cs.purdue.edu>; Sun, 11 Feb 90 21:30:08 -0500
  18. Message-Id: <9002120230.AA19140@raid8.cs.purdue.edu>
  19. To: dl@oswego.oswego.edu
  20. Subject: kudos for profiling and libg++
  21. In-Reply-To: Your message of Tue, 09 Jan 90 06:27:17 -0500.
  22.              <9001091127.AA09544@g.oswego.edu> 
  23. Date: Sun, 11 Feb 90 21:30:04 EST
  24. From: riedl@cs.purdue.edu
  25.  
  26. *** EOOH ***
  27. Return-Path: <riedl@cs.purdue.edu>
  28. To: dl@oswego.oswego.edu
  29. Subject: kudos for profiling and libg++
  30. In-Reply-To: Your message of Tue, 09 Jan 90 06:27:17 -0500.
  31.              <9001091127.AA09544@g.oswego.edu> 
  32. Date: Sun, 11 Feb 90 21:30:04 EST
  33. From: riedl@cs.purdue.edu
  34.  
  35. I was having some trouble with the performance of a concurrency
  36. controller I had written, and am very pleased to report that g++
  37. support for profiling, and the excellent libg++ data structure support
  38. saved the day!  I include a detailed description of the problem and
  39. solution below, which you are welcome to send to any of the involved
  40. parties for encouragement, or to publish for bragging rights (:-).
  41.  
  42. Nice job!
  43. John
  44. ------
  45. The basic problem was that two concurrency controllers that I had
  46. written, called T/O and Lock for short, should have had similar
  47. performance characteristics, but didn't.  After some days of work it
  48. became clear that T/O was significantly slower than Lock, for reasons
  49. that I couldn't understand.  I profiled the two routines and found the
  50. profiles to be very similar, as expected, with the exception of a
  51. large number of calls to compare_item in T/O:
  52.  
  53.     calls to compare_item       total time
  54. T/O    118,112       0.43               10.76 seconds
  55. LOCK    6601*[2-3] 0.09 seconds        9.02 seconds
  56.  
  57. (The numbers involved are small because I did the run for 100
  58. transactions.  Real runs will be for several orders of magnitude more
  59. transactions.) 
  60.  
  61. (I don't have an exact number for the number of calls to compare item
  62. for Lock for obscure reasons, but my understanding of the program
  63. makes me confident that it was called 2-3 times for each call to its
  64. parent, which was called 6601 times.)
  65.  
  66. The additional 1.74 seconds spent in T/O could almost all be accounted
  67. for by calls to compare_item and its parent, SLSet::seek.  Since the
  68. data structures involved were relatively small I expected that using a
  69. fancier data structure wouldn't help, but I thought I should test the
  70. potential.  I determined that the data structures involved would grow
  71. to about 300 items, and that items would be accessed much more often
  72. than they would be inserted.  So I timed versions using the linked
  73. list and using AVL trees:
  74.  
  75. program        items    accesses    seconds (user time)
  76. sl-set         300     10,000              7.70
  77. sl-set         300     10,000              7.61
  78. sl-set        3000     10,000             91.35
  79.  
  80. avl-set         300      1,000       0.18
  81. avl-set         300     10,000       0.68
  82. avl-set         300    100,000          6.15
  83. avl-set        3000     10,000          1.48
  84.  
  85. Clearly the AVL tree implementation was far superior, even for small
  86. problem sizes.  I installed the AVL sets in T/O and they solved the
  87. performance problem I was having.  Profiling shows that before the
  88. change:
  89.  
  90.     calls to compare_item       total time
  91. T/O    118,112       0.43               10.76 seconds
  92. LOCK    6601*[2-3] 0.09 seconds        9.02 seconds
  93.  
  94. After the change locking is the same, but:
  95.  
  96. T/O    16,048     0.10 seconds        9.08 seconds
  97.  
  98. The lessons I take from this study are:
  99.  
  100. 1) Linked lists may cause performance problems even if the lists are
  101. relatively short (< 100 items) if they are heavily used.
  102.  
  103. 2) The C++ library can be extremely advantageous.  In this case, I
  104. made a two line change to my program to change to AVL trees.
  105.  
  106. 3) Profiling is essential to understanding program performance.
  107.  
  108. John Riedl
  109.  
  110. 
  111. 1,,
  112. Return-Path: <dl@g.oswego.edu>
  113. Received: from rocky.Oswego.EDU by g.oswego.edu (4.0/SMI-4.0)
  114.     id AA03598; Thu, 8 Feb 90 05:50:05 EST
  115. Received: by oswego.Oswego.EDU (5.57/Osw4.1.21)
  116.     id AA08592; Thu, 8 Feb 90 05:47:12 EST
  117. Received: from life.ai.mit.edu by nisc.nyser.net (5.61/2.1-NYSERNet NISC)
  118.     id AA07649; Thu, 8 Feb 90 05:44:40 -0500
  119. Received: from oswego.Oswego.EDU by life.ai.mit.edu (4.0/AI-4.10) id AA29896; Thu, 8 Feb 90 05:46:04 EST
  120. Received: by oswego.Oswego.EDU (5.57/Osw4.1.21)
  121.     id AA27161; Thu, 8 Feb 90 05:48:41 EST
  122. Received: by g.oswego.edu (4.0/SMI-4.0)
  123.     id AA03595; Thu, 8 Feb 90 05:48:50 EST
  124. Date: Thu, 8 Feb 90 05:48:50 EST
  125. From: dl@g.oswego.edu (Doug Lea)
  126. Message-Id: <9002081048.AA03595@g.oswego.edu>
  127. To: jose@csserver.cs.msstate.edu
  128. Cc: bug-lib-g++@prep.ai.mit.edu
  129. In-Reply-To: Jose Cordova's message of Wed, 7 Feb 90 17:28:57 CST <9002072328.AA07167@CSServer.CS.MsState.Edu>
  130. Subject: Run-time error when using 'get' with an istream object
  131. Reply-To: dl@oswego.oswego.edu
  132.  
  133. *** EOOH ***
  134. Return-Path: <dl@g.oswego.edu>
  135. Date: Thu, 8 Feb 90 05:48:50 EST
  136. From: dl@g.oswego.edu (Doug Lea)
  137. To: jose@csserver.cs.msstate.edu
  138. Cc: bug-lib-g++@prep.ai.mit.edu
  139. In-Reply-To: Jose Cordova's message of Wed, 7 Feb 90 17:28:57 CST <9002072328.AA07167@CSServer.CS.MsState.Edu>
  140. Subject: Run-time error when using 'get' with an istream object
  141. Reply-To: dl@oswego.oswego.edu
  142.  
  143.  
  144. > I am having trouble using the 'get' method for the 'istream' class.
  145. > It generates a 'Segmentation fault' error at run-time.  I know the
  146. > 'istream' is being opened correctly because reading into a 'String'
  147. > object with >> works fine.  Am I doing something wrong ?
  148. > The sample program and "data" illustrate the point:
  149. > main()
  150. > {
  151. >     istream from("data",io_readonly,a_useonly);
  152. >     char *line;
  153. >     from.get(line,15);
  154. >     cout << line;
  155. > }
  156. > Sample "data" file contents:
  157. > word1 word2
  158. > word3
  159.  
  160. There are 3 istream functions for reading char*'s 
  161.  
  162.   istream&      get    (char* s, int n, char terminator = '\n');
  163.   istream&      getline(char* s, int n, char terminator = '\n');
  164.   istream&      gets   (char **s, char terminator = '\n');
  165.  
  166. The first two *require* an allocated char* (they differ only
  167. in how the trailing terminator is handled.) To use them, you
  168. must supply either a char[N] or an allocated char*.
  169. The third automatically allocates space for you, that you should
  170. later delete.
  171.  
  172. For example,
  173.  
  174. main()
  175. {
  176.     istream from("data",io_readonly,a_useonly);
  177.     char *line = new char[16]; // enough for string + null
  178.     char line2[16];
  179.     char* line3 = 0; // `= 0' so delete'able even if never allocated --
  180.                      // Not necessary in this example.
  181.  
  182.     from.get(line,15);
  183.     from.get(line2,15);
  184.     from.gets(&line3,15);  // pass in the addr of line3
  185.  
  186.     cout << line;
  187.     cout << line2;
  188.     cout << line3;
  189.  
  190.     delete line;
  191.     delete line3;
  192. }
  193.  
  194. Using the String class is a very good way to avoid dealing with these
  195. kinds of char* allocation and semantics issues.
  196.  
  197. -Doug
  198.  
  199. 
  200. 1, answered,,
  201. Return-Path: <chowkwan@aerospace.aero.org>
  202. Received: from aerospace.aero.org ([130.221.192.10]) by g.oswego.edu (4.0/SMI-4.0)
  203.     id AA03846; Mon, 5 Feb 90 16:10:27 EST
  204. Received: from antares.aero.org by aerospace.aero.org with SMTP (5.61++/6.0.GT)
  205.     id AA24377 for dl@g.oswego.edu; Mon, 5 Feb 90 13:06:58 -0800
  206. Posted-Date: Mon, 5 Feb 90 13:06:50 PST
  207. Received: from merlin.aero.org by antares.aero.org (4.1/SMI-3.2-A4ant)
  208.     id AA20056 for dl@g.oswego.edu; Mon, 5 Feb 90 13:06:55 PST
  209. Message-Id: <9002052106.AA20056@antares.aero.org>
  210. Received: by merlin.aero.org (4.1/SMI-3.2-A4)
  211.     id AA03654 for dl@g.oswego.edu; Mon, 5 Feb 90 13:06:50 PST
  212. Date: Mon, 5 Feb 90 13:06:50 PST
  213. From: chowkwan@aerospace.aero.org
  214. To: dl@g.oswego.edu
  215. Subject: Checklist for using Map class
  216.  
  217. *** EOOH ***
  218. Return-Path: <chowkwan@aerospace.aero.org>
  219. Posted-Date: Mon, 5 Feb 90 13:06:50 PST
  220. Date: Mon, 5 Feb 90 13:06:50 PST
  221. From: chowkwan@aerospace.aero.o