Author Topic: New timing macros  (Read 1183 times)

TimoVJL

  • Member
  • *****
  • Posts: 1001
Re: New timing macros
« Reply #30 on: May 20, 2022, 08:27:07 AM »
Code: [Select]
AMD Athlon(tm) II X2 220 Processor
+0       Cycles for PI*100
+17      Cycles for PI*100/10
+1       Cycles for push & pop eax
+0       Cycles for empty loop
+16      Cycles for 10 * inc & dec eax
+16      Cycles for 10 * add eax,1 & sub eax,1
+16      Cycles for 10 * inc+dec with lea
481     kCycles for finding 'Duplicate' in Window.inc
+471     Cycles for finding 'test' with InString

+0       Cycles for PI*100
+17      Cycles for PI*100/10
+0       Cycles for push & pop eax
+0       Cycles for empty loop
+16      Cycles for 10 * inc & dec eax
+16      Cycles for 10 * add eax,1 & sub eax,1
+16      Cycles for 10 * inc+dec with lea
481     kCycles for finding 'Duplicate' in Window.inc
+476     Cycles for finding 'test' with InString

+0       Cycles for PI*100
+17      Cycles for PI*100/10
+1       Cycles for push & pop eax
+0       Cycles for empty loop
+16      Cycles for 10 * inc & dec eax
+16      Cycles for 10 * add eax,1 & sub eax,1
+16      Cycles for 10 * inc+dec with lea
481     kCycles for finding 'Duplicate' in Window.inc
+477     Cycles for finding 'test' with InString

+0       Cycles for PI*100
+17      Cycles for PI*100/10
+0       Cycles for push & pop eax
+0       Cycles for empty loop
+16      Cycles for 10 * inc & dec eax
+16      Cycles for 10 * add eax,1 & sub eax,1
+16      Cycles for 10 * inc+dec with lea
481     kCycles for finding 'Duplicate' in Window.inc
+477     Cycles for finding 'test' with InString

more (y)?

May the source be with you

jj2007

  • Member
  • *****
  • Posts: 12479
  • Assembler is fun ;-)
    • MasmBasic
Re: New timing macros
« Reply #31 on: May 20, 2022, 09:27:26 AM »
Thanks @everybody :thup:

I attach a new graphical version. Two interesting aspects:
- when sizing the window, the cycle count for ...
      fldpi
      fdiv FP4(0.1)
      fstp st
... is pretty stable at 18 cycles for my macros and 14 cycles for Michael Webster's macros. Why that difference? I can only guess that my "isolation" of the core code with nops all over the place place a role:

Code: [Select]
Address   Hex dump          Command                                  Comments
00401403   .  0FA2          .cpuid
00401405   .  0F31          .rdtsc
00401407   .  A3 F0A34000   .mov [CyCtrdtsc], eax
0040140C   .  8915 F4A34000 .mov [40A3F4], edx
00401412   .  8B1D E4A34000 .mov ebx, [CyCtinner]
00401418   .  90            .nop
00401419   .  90            .nop
0040141A   .  90            .nop
0040141B   .  90            .nop
0040141C   .  90            .nop
0040141D   .  90            .nop
0040141E   .  90            .nop
0040141F   .  90            .nop
00401420   >  D9EB          .fldpi                                   ; loop start ---------------------
00401422   .  D835 68904000 .fdiv dword ptr [??0232]                 ; float 0.1000000
00401428   .  DDD8          .fstp st
0040142A   .  90            .nop
0040142B   .  90            .nop
0040142C   .  90            .nop
0040142D   .  90            .nop
0040142E   .  90            .nop
0040142F   .  90            .nop
00401430   .  90            .nop
00401431   .  90            .nop
00401432   .  4B            .dec ebx
00401433   .^ 79 EB         .jns short CyCtcode2_s                   ; jump back ---------------------
00401435   .  50            .push eax
00401436   .  51            .push ecx
00401437   .  52            .push edx
00401438   .  33C0          .xor eax, eax
0040143A   .  0FA2          .cpuid
0040143C   .  0F31          .rdtsc

HSE

  • Member
  • *****
  • Posts: 2088
  • AMD 7-32 / i3 10-64
Re: New timing macros
« Reply #32 on: May 20, 2022, 09:55:41 AM »
 :biggrin:

Perhaps is a bad idea to take the timing at same time that paint (you are not calling for High Priority¿?):
Equations in Assembly: SmplMath

jj2007

  • Member
  • *****
  • Posts: 12479
  • Assembler is fun ;-)
    • MasmBasic
Re: New timing macros
« Reply #33 on: May 20, 2022, 10:02:13 AM »
Perhaps is a bad idea to take the timing at same time that paint.:

Well, it's not taken during the WM_PAINT processing. But apparently there is an influence. When quickly sizing the window (lots of painting), the cycle counts go down, though. I have absolutely no clue why that is so.

Anyway, for timing your algo you would use a console program. The GUI version is for illustrative purposes, i.e. for showing the skewed distribution of results.

To build the source attached above, you need the latest MasmBasic version of 20 May 2022.

hutch--

  • Administrator
  • Member
  • ******
  • Posts: 9369
  • Mnemonic Driven API Grinder
    • The MASM32 SDK
Re: New timing macros
« Reply #34 on: May 20, 2022, 10:48:51 AM »
mOST RECENT VERSION !

Intel(R) Core(TM) i7-5820K CPU @ 3.30GHz
+1       Cycles for PI*100
+12      Cycles for PI*100/10
+2       Cycles for push & pop eax
+0       Cycles for empty loop
+14      Cycles for 10 * inc & dec eax
+14      Cycles for 10 * add eax,1 & sub eax,1
+14      Cycles for 10 * inc+dec with lea
187     kCycles for finding 'Duplicate' in Window.inc
+145     Cycles for finding 'test' with InString

+1       Cycles for PI*100
+12      Cycles for PI*100/10
+2       Cycles for push & pop eax
+0       Cycles for empty loop
+14      Cycles for 10 * inc & dec eax
+14      Cycles for 10 * add eax,1 & sub eax,1
+14      Cycles for 10 * inc+dec with lea
187     kCycles for finding 'Duplicate' in Window.inc
+144     Cycles for finding 'test' with InString

+1       Cycles for PI*100
+12      Cycles for PI*100/10
+2       Cycles for push & pop eax
+0       Cycles for empty loop
+14      Cycles for 10 * inc & dec eax
+14      Cycles for 10 * add eax,1 & sub eax,1
+14      Cycles for 10 * inc+dec with lea
187     kCycles for finding 'Duplicate' in Window.inc
+144     Cycles for finding 'test' with InString

+1       Cycles for PI*100
+12      Cycles for PI*100/10
+2       Cycles for push & pop eax
+0       Cycles for empty loop
+14      Cycles for 10 * inc & dec eax
+14      Cycles for 10 * add eax,1 & sub eax,1
+14      Cycles for 10 * inc+dec with lea
187     kCycles for finding 'Duplicate' in Window.inc
+143     Cycles for finding 'test' with InString

more (y)?


What is the "more (y)?" for ?  :tongue:
hutch at movsd dot com
http://www.masm32.com    :biggrin:  :skrewy:

jj2007

  • Member
  • *****
  • Posts: 12479
  • Assembler is fun ;-)
    • MasmBasic
Re: New timing macros
« Reply #35 on: May 20, 2022, 06:29:08 PM »
What is the "more (y)?" for ?  :tongue:

Be courageous, type y :biggrin:

hutch--

  • Administrator
  • Member
  • ******
  • Posts: 9369
  • Mnemonic Driven API Grinder
    • The MASM32 SDK
Re: New timing macros
« Reply #36 on: May 20, 2022, 06:43:48 PM »
I did, nothing happened apart from exiting, is that what the "y" is for ?  :tongue:
hutch at movsd dot com
http://www.masm32.com    :biggrin:  :skrewy:

jj2007

  • Member
  • *****
  • Posts: 12479
  • Assembler is fun ;-)
    • MasmBasic
Re: New timing macros
« Reply #37 on: May 20, 2022, 07:01:24 PM »
Strange, I get this from reply #27:

Code: [Select]
more (y)?

+73      Cycles for fldpi+1*fdiv+fstp st
+12     kCycles for finding 'test' with Instr_
328     kCycles for finding 'Duplicate' with Instr_
2492    kCycles for finding 'Duplicate' with InString
2553    kCycles for finding 'Duplicate' with crt strstr
720     kCycles for finding 'Duplicate' with Boyer-Moore

+16      Cycles for fldpi+1*fdiv+fstp st
+3286    Cycles for finding 'test' with Instr_
192     kCycles for finding 'Duplicate' with Instr_
2496    kCycles for finding 'Duplicate' with InString
2560    kCycles for finding 'Duplicate' with crt strstr
720     kCycles for finding 'Duplicate' with Boyer-Moore

+16      Cycles for fldpi+1*fdiv+fstp st
+3286    Cycles for finding 'test' with Instr_
192     kCycles for finding 'Duplicate' with Instr_
2494    kCycles for finding 'Duplicate' with InString
2560    kCycles for finding 'Duplicate' with crt strstr
719     kCycles for finding 'Duplicate' with Boyer-Moore

+17      Cycles for fldpi+1*fdiv+fstp st
+3309    Cycles for finding 'test' with Instr_
192     kCycles for finding 'Duplicate' with Instr_
2493    kCycles for finding 'Duplicate' with InString
2555    kCycles for finding 'Duplicate' with crt strstr
720     kCycles for finding 'Duplicate' with Boyer-Moore

+16      Cycles for fldpi+1*fdiv+fstp st
+3313    Cycles for finding 'test' with Instr_
192     kCycles for finding 'Duplicate' with Instr_
2491    kCycles for finding 'Duplicate' with InString
2558    kCycles for finding 'Duplicate' with crt strstr
720     kCycles for finding 'Duplicate' with Boyer-Moore

hit any key

felipe

  • Member
  • *****
  • Posts: 1381
Re: New timing macros
« Reply #38 on: May 24, 2022, 04:01:59 AM »
Hi all, long time since my last reply/post in the forum  :sad:. One question please: generally speaking, what would be more accurate to test performance in a windows program, counting cycles or counting time (with QueryPerformanceCounter)?

daydreamer

  • Member
  • *****
  • Posts: 1994
  • "follow the blue star!!!"
Re: New timing macros
« Reply #39 on: May 24, 2022, 04:57:15 AM »
Hi all, long time since my last reply/post in the forum  :sad:. One question please: generally speaking, what would be more accurate to test performance in a windows program, counting cycles or counting time (with QueryPerformanceCounter)?
Welcome back felipe  :thumbsup:
Counting cycles,but invoke gettimemillis before and after easier to compare between your asm program and other languages timings for example very fast, huge fibonnaci calculations with matrices
http://masm32.com/board/index.php?topic=9773.0

SIMD fan and macro fan
I am an Invoker
"An Invoker is a mage who specializes in the manipulation of raw and elemental energies."
Teacher "REAL8 + QWORD is like apples and oranges,you cant mix them"
Student "ofcourse you can,it becomes a fruit salad" :)

jj2007

  • Member
  • *****
  • Posts: 12479
  • Assembler is fun ;-)
    • MasmBasic
Re: New timing macros
« Reply #40 on: May 24, 2022, 06:39:49 AM »
counting cycles or counting time

Time varies with cpu speed, cycles don't.

invoke gettimemillis before and after

Interesting, can you post an example using gettimemillis?

felipe

  • Member
  • *****
  • Posts: 1381
Re: New timing macros
« Reply #41 on: May 24, 2022, 07:24:07 AM »
This is an interesting topic. Let me put a quote from a page of intel about clock cycles to help a little bit to new ones (like my self  :toothy:):

Quote
Sometimes, multiple instructions are completed in a single clock cycle; in other cases, one instruction might be handled over multiple clock cycles. Since different CPU designs handle instructions differently, it’s best to compare clock speeds within the same CPU brand and generation.

For example, a CPU with a higher clock speed from five years ago might be outperformed by a new CPU with a lower clock speed, as the newer architecture deals with instructions more efficiently. An X-series Intel® processor might outperform a K-series processor with a higher clock speed, because it splits tasks between more cores and features a larger CPU cache. But within the same generation of CPUs, a processor with a higher clock speed will generally outperform a processor with a lower clock speed across many applications. This is why it’s important to compare processors from the same brand and generation.

https://www.intel.com/content/www/us/en/gaming/resources/cpu-clock-speed.html

hutch--

  • Administrator
  • Member
  • ******
  • Posts: 9369
  • Mnemonic Driven API Grinder
    • The MASM32 SDK
Re: New timing macros
« Reply #42 on: May 24, 2022, 07:37:19 AM »
Hi felipe,

Don't be lead astray, the only reliable timing technique is real time[tm]. Any recent CPU does many things that effect trying to perform close range timings, variable frequency depending on load, OS ring0 over-rides, core sharing, CPU time slicing, CPU hardware differences etc etc etc ....

Timing is at best unreliable due to these factors and the best I have come up with over many years is to design each test to match the algo's usage. Run the test for long enough, (over 1 second usually does the job). With the choice of attack speed versus sustained data transfer and everything inbetween.

Short duration tests run many times versus long duration tests for absolute transfer speed.
hutch at movsd dot com
http://www.masm32.com    :biggrin:  :skrewy:

felipe

  • Member
  • *****
  • Posts: 1381
Re: New timing macros
« Reply #43 on: May 24, 2022, 07:59:48 AM »
I share that vision Hutch, i mean, if you can see the program running fast then you finished the job. If you want your program to run fast on multiple cpu's, you test the program in all the different cpu's you can. If you have the task of constructing the fastest program in the world, you will still need to face the reallity that the program will run different in two different cpu's.  :icon_idea:

Although i recognize that counting cycles, i mean, bringing out strange numbers from this electronic world, can be fun... :mrgreen:

quarantined

  • Regular Member
  • *
  • Posts: 42
Re: New timing macros
« Reply #44 on: May 24, 2022, 08:41:34 AM »
off topic == on

Hi all, long time since my last reply/post in the forum

Well, hello. I haven’t seen you around here since forever. How are you?

off topic == off. Oops