home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / OL.LZH / PROCS.LZH / IBENCH.ICN < prev    next >
Text File  |  1991-09-05  |  4KB  |  167 lines

  1. ############################################################################
  2. #
  3. #    Name:    ibench.icn
  4. #
  5. #    Title:    Support procedures for Icon benchmarking.
  6. #
  7. #    Author:    Ralph E. Griswold
  8. #
  9. #    Date:    September 2, 1991
  10. #
  11. ############################################################################
  12. #
  13. #     Procedures to support benchmarking of Icon programs:
  14. #
  15. #     Init__(prog)        initialize for benchmarking
  16. #     Term__()        terminate benchmarking
  17. #     Allocations__()    get amounts allocated
  18. #     Collections__()    get collections
  19. #     Regions__()        get regions
  20. #     Signature__()        show program/environment information
  21. #     Storage__()        get storage
  22. #     Time__()        show elapsed time
  23. #     Display__(data,name)    show information
  24. #
  25. ############################################################################
  26. #
  27. #     The code to be timed is bracketed by calls to Init__(name)
  28. #  and Term__(), where name is used for tagging the results.
  29. #  The typical usage is:
  30. #
  31. #    procedure main()
  32. #       [declarations]
  33. #       Init__(name)
  34. #        .
  35. #        .
  36. #        .
  37. #       Term__()
  38. #    end
  39. #
  40. #     If the environment variable OUTPUT is set, program output is
  41. #  not suppressed.
  42. #
  43. #     If the environment varibale NOBENCH is set, benchmarking is not
  44. #  performed (and OUTPUT has no effect).  This allows a program that
  45. #  links ibench to run in the ordinary way.
  46. #
  47. #################################################################
  48.  
  49. global Save__, Saves__, Name__, Labels__
  50.  
  51. # List information before running.
  52. #
  53. procedure Init__(prog)
  54.    if getenv("NOBENCH") then {    # don't do benchmarking
  55.       Term__ := 1
  56.       return
  57.       }
  58.    Name__ := prog            # program name
  59.    Labels__ := ["total ","static","string","block "]
  60.    write(Name__,": benchmarking\n")
  61.    Signature__()            # initial information
  62.    Regions__()
  63.    Time__()
  64.    if not getenv("OUTPUT") then {    # if OUTPUT is set, allow output
  65.       Save__ := write            # turn off output
  66.       Saves__ := writes
  67.       write := writes := 1
  68.       }
  69.    else write(Name__,": output\n")
  70.    return
  71. end
  72.  
  73. # List information at termination.
  74.  
  75. procedure Term__()
  76.    if not getenv("OUTPUT") then {    # if OUTPUT is not set, restore output
  77.       write := Save__
  78.       writes := Saves__
  79.       }
  80.                     # final information
  81.    Regions__()
  82.    Storage__()
  83.    Collections__()
  84.    Allocations__()
  85.    write("\n",Name__,": elapsed time = ",Time__()," ms.")
  86.    return
  87. end
  88.  
  89. #
  90. # List total amounts of allocation.  Need Icon Version 8.5 or above
  91. # (remove comments below to enable).
  92. #
  93. procedure Allocations__()
  94.    local allocations
  95.  
  96. #  allocations := []
  97. #  every put(allocations,&allocations)
  98. #  Display__(allocations,"allocations")
  99.    return
  100.  
  101. end
  102.  
  103. # List garbage collections performed.
  104. #
  105. procedure Collections__()
  106.    local collections
  107.  
  108.    collections := []
  109.    every put(collections,&collections)
  110.    Display__(collections,"collections")
  111.    return
  112. end
  113.  
  114. # List region sizes.
  115. #
  116. procedure Regions__()
  117.    local regions, count
  118.    
  119.    regions := []
  120.    every put(regions,®ions)
  121.    count := 0
  122.    every count +:= !regions
  123.    push(regions,count)
  124.    Display__(regions,"regions")
  125.    return
  126. end
  127.  
  128. # List relveant implementation information
  129. #
  130. procedure Signature__()
  131.  
  132.    every write(&version | &host | &features)
  133.    return
  134.  
  135. end
  136.  
  137. # List storage used.
  138. #
  139. procedure Storage__()
  140.    local storage, count
  141.    
  142.    storage := []
  143.    every put(storage,&storage)
  144.    count := 0
  145.    every count +:= !storage
  146.    push(storage,count)
  147.    Display__(storage,"storage")
  148.    return
  149. end
  150.  
  151. # List elapsed time.
  152. #
  153. procedure Time__()
  154.    static lasttime
  155.  
  156.    initial lasttime := &time
  157.    return &time - lasttime
  158. end
  159.  
  160. # Display storage information
  161. #
  162. procedure Display__(data,name)
  163.    write("\n",name,":\n")
  164.    every i := 1 to *Labels__ do
  165.       write(Labels__[i],right(data[i],8))
  166. end
  167.