Author Topic: Open, Read, Close: Distribution of the duration  (Read 1069 times)

jj2007

  • Member
  • *****
  • Posts: 8776
  • Assembler is fun ;-)
    • MasmBasic
Open, Read, Close: Distribution of the duration
« on: November 28, 2017, 10:37:25 PM »
A simple Windows app showing the distribution of the timings of an Open/Read/Close sequence, here for a Win7-64 system:

include \masm32\MasmBasic\Res\MbGui.asm        ; OPT_Icon Calc
  SetGlobals total, median
  loops=1000
  Dim ms() As DWORD
  For_ ecx=0 To loops-1
        NanoTimer()
        Open "I", #1, "\Masm32\include\Windows.inc"     ; open, read, close
        Let esi=Input$(#1, 4096)
        Close #1
        add total, NanoTimer(us)
        mov ms(ecx), eax
  Next
  ArraySort ms()

Event Paint
  ArrayPlot RgbCol(222, 240, 255)       ; init & set background
  ArrayPlot ms(), 0, lines=3, 00100204h        ; draw the array with 3px lines and left top right bottom margins
  ArrayPlot exit, "Duration of an Open, Read, Close sequence"   ; finish with a title
  GuiTextBox 20.0-60, 60.0, 120, 64, Str$("Bottom 10pc: %i microseconds\n", ms(loops/10))
  GuiTextBox 50.0-60, 60.0, 120, 64, Cat$(Str$("Average: %i microseconds\n", total/loops)+Str$("Median: %i microseconds", ms(loops/2)))
  GuiTextBox 80.0-60, 60.0, 120, 64, Str$("Top 10pc: %i microseconds\n", ms(loops-loops/10))
EndOfCode

jj2007

  • Member
  • *****
  • Posts: 8776
  • Assembler is fun ;-)
    • MasmBasic
Re: Open, Read, Close: Distribution of the duration
« Reply #1 on: November 30, 2017, 01:35:24 AM »
New version, with more precise timings for the following functions:
- GetHash
- getting 1000 random numbers from CRT rand()
- wRec$(), i.e. translation from Ansi to Unicode of a 100+ chars string
- an Open/Input$/Close sequence

The pattern is very clear, I suppose: 98% of all values are near the median, then there are a few outliers. Source and executables are attached, there is a variable choice=... which allows to build for one of the tests. Building requires MasmBasic 29 Nov 2017.




jimg

  • Member
  • ***
  • Posts: 275
Re: Open, Read, Close: Distribution of the duration
« Reply #2 on: December 01, 2017, 02:07:10 AM »
For PlotOpenReadClose, I get a bunch of
"The handle is invalid.   eip 0040538E"
until I hit cancel, then it runs.

jj2007

  • Member
  • *****
  • Posts: 8776
  • Assembler is fun ;-)
    • MasmBasic
Re: Open, Read, Close: Distribution of the duration
« Reply #3 on: December 01, 2017, 02:15:11 AM »
For PlotOpenReadClose, I get a bunch of
"The handle is invalid.   eip 0040538E"
until I hit cancel, then it runs.

Code: [Select]
Open "I", #1, "\Masm32\include\Windows.inc" ; open, read, close
Let esi=Input$(#1, 4096)  ; yours chokes here <<<<<<<<<<<<<<<<
Close #1

If you launch that exe from your \Masm32 folder, do you still get that box?

jimg

  • Member
  • ***
  • Posts: 275
Re: Open, Read, Close: Distribution of the duration
« Reply #4 on: December 02, 2017, 01:56:44 AM »
I should have looked at the code.  It works fine on the drive containing the masm32 folder.  I normally run these tests on a separate ram drive.