FreeBasic ::  :: 

    

  Vadim Weinberg 06, 2014 2:46 am

1.
.
:

/' 1.

.
1.
2 .

1
- 1 ( intA+=1 intA=intA+1)
- 1 #Define ( intA+=1 intA=intA+1)
- =1 ( intA+=iOne intA=intA+iOne)
- =1 ( intA+=iONE intA=intA+iONE)
- ( inc eax add eax, 1. inc )

/.
 
, , .
'/
#Include "string.bi" ' Format() .

Namespace Class1' Namespace, .. (FbEdit) "".
 Type Bench ' , , .
  Declare Sub Start(As String,ByRef As Integer) ' , , - .
  Declare Sub Finish() '- , .
  Declare Sub Record() ' .
  Private:' Private? ? ...
  T1 As Double ' .
  T2 As Double ' .
  Num_Test As UShort=0 '
  Record_Tmp As String ' , Start Finish .
  Record_MAX_Name As String ' .
  Record_MAX_Num As Double=0 ' .
  Record_MIN_Name As String ' .
  Record_MIN_Num As Double=1000 ' .
 End Type
 Sub Bench.Start(tName As String,ByRef i As Integer)' , , - .
  i=0 ' "" (aInt), " "(2147483646). , ByRef.
  Record_Tmp=tName ' Finish, .
  Num_Test+=1 ' .
  ? Space(4-Len(Str(Num_Test)))&Str(Num_Test)&": "& tName &" "&String(50-Len(tName),45)&" ";' ( ).
  T1=Timer' !!!! Ѩ . .
 End Sub
 Sub Bench.Finish()'- , .
  T2=Timer-T1' !!! ( ).
  ? Format(T2 ," ##0.0000 ")' .
  If T2<Record_MIN_Num Then ' .
  Record_MIN_Name = Record_Tmp: Record_MIN_Num = T2 ' .
  EndIf
  If T2>Record_MAX_Num Then ' .
  Record_MAX_Name = Record_Tmp: Record_MAX_Num = T2 ' .
  EndIf
 End Sub
 Sub Bench.Record' .
  ?
  ? "MIN - "; Format(Record_MIN_Num," ##0.0000 "), Record_MIN_Name ' .
  ? "DIF - "; Format(100-100*(Record_MIN_Num/Record_MAX_Num),"#0.00");"%"' .
  ? "MAX - "; Format(Record_MAX_Num," ##0.0000 "), Record_MAX_Name ' .
  ?
  ? !"END\7":Sleep 'Ѩ! END-BEEP-SLEEP.
 End Sub
End Namespace' Class1

Dim Test As Class1.Bench ' . , - .

Const MaxI=2147483646 ' "" .
Dim As Integer aInt '"". 1.
Dim As Integer iOne=1 ' Integer
Const As Integer C_ONE=1 ' Integer
#Define dINTEGER 1 ' #Define

' ? , . . , .
' "": 0 MaxI :|==== ====|:Next: "", .
Test.start("Integer+=1",aInt) :For n As UInteger=0 To MaxI: aInt+=1 :Next:Test.Finish
Test.start("Integer=Integer+1",aInt) :For n As UInteger=0 To MaxI: aInt=aInt+1 :Next:Test.Finish
Test.start("Integer+=Integer",aInt) :For n As UInteger=0 To MaxI: aInt+=iOne :Next:Test.Finish
Test.start("Integer=Integer+Integer",aInt):For n As UInteger=0 To MaxI: aInt=aInt+iOne :Next:Test.Finish
Test.start("Integer+=Const",aInt) :For n As UInteger=0 To MaxI: aInt+=C_ONE :Next:Test.Finish
Test.start("Integer=Integer+Const",aInt) :For n As UInteger=0 To MaxI: aInt=aInt+C_ONE :Next:Test.Finish
Test.start("Integer+=#Define",aInt) :For n As UInteger=0 To MaxI: aInt+=dINTEGER :Next:Test.Finish
Test.start("Integer=Integer+#Define",aInt):For n As UInteger=0 To MaxI: aInt=aInt+dINTEGER :Next:Test.Finish
Test.start("Asm inc eax (Integer)",aInt) :For n As UInteger=0 To MaxI: : :
: : : Asm mov eax, [aInt]' :
: : : Asm inc eax ' :
: : : Asm mov [aInt], eax' :
: : : :Next:Test.Finish
Test.start("Asm add eax, 1(Integer)",aInt):For n As UInteger=0 To MaxI: : :
: : : Asm mov eax, [aInt]' :
: : : Asm add eax, 1 ' :
: : : Asm mov [aInt], eax' :
: : : :Next:Test.Finish
' "": 0 MaxI :|==== ====|:Next: "", .

' ? .
Dim As UInteger aUInt '"". 1.
Dim As UInteger uiOne=1 ' UInteger
Const As UInteger C_UONE=1' Integer

' .
' Start(As String,ByRef As Integer) Integer ByRef,
' UInteger, ... , , ByRef?

' "" : 0 MaxI :|==== ====|:Next: "", .
Test.start("UInteger+=1",aUInt) :For n As UInteger=0 To MaxI: aUInt+=1 :Next:Test.Finish
Test.start("UInteger=UInteger+1",aUInt) :For n As UInteger=0 To MaxI: aUInt=aUInt+1 :Next:Test.Finish
Test.start("UInteger+=UInteger",aUInt) :For n As UInteger=0 To MaxI: aUInt+=uiOne :Next:Test.Finish
Test.start("UInteger=UInteger+UInteger",aUInt):For n As UInteger=0 To MaxI: aUInt=aUInt+uiOne :Next:Test.Finish
Test.start("UInteger+=UConst",aUInt) :For n As UInteger=0 To MaxI: aUInt+=C_UONE :Next:Test.Finish
Test.start("UInteger=UInteger+UConst",aUInt) :For n As UInteger=0 To MaxI: aUInt=aUInt+C_UONE :Next:Test.Finish
Test.start("UInteger+=#Define",aUInt) :For n As UInteger=0 To MaxI: aUInt+=dINTEGER :Next:Test.Finish
Test.start("UInteger=UInteger+#Define",aUInt) :For n As UInteger=0 To MaxI: aUInt=aUInt+dINTEGER:Next:Test.Finish
Test.start("Asm inc eax (UInteger)",aUInt) :For n As UInteger=0 To MaxI: : :
: : : Asm mov eax, [aUInt]' :
: : : Asm inc eax ' :
: : : Asm mov [aUInt], eax' :
: : : :Next:Test.Finish
Test.start("Asm add eax, 1 (UInteger)",aUInt) :For n As UInteger=0 To MaxI: : :
: : : Asm mov eax, [aUInt]' :
: : : Asm Add eax, 1 ' :
: : : Asm mov [aUInt], eax' :
: : : :Next:Test.Finish
' "" : 0 MaxI :|==== ====|:Next: "", .

' .
Test.Record' .

'P.S. . .


  1. . Asm add eax, 1. .
  2. . .
  3. 5-10%.
  4. ( 1,5-1,7 ) . .
  5. FB 1 , FB v0.91. 59 51 Kb . .

FB ASM inc , 1 (Const, #Define +1).


Dim As Integer aInteger
aInteger+=666

' , 1.

sub esp, 4
.Lt_0002:
mov dword ptr [ebp-4], 0
add dword ptr [ebp-4], 666

Dim As Integer aInteger
aInteger+=1

' .

sub esp, 4
.Lt_0002:
mov dword ptr [ebp-4], 0
inc dword ptr [ebp-4]

Dim As Integer aInteger
aInteger=aInteger+1

' .

sub esp, 4
.Lt_0002:
mov dword ptr [ebp-4], 0
inc dword ptr [ebp-4]

Dim As Integer aInteger
Dim As Integer bInteger=1
aInteger=aInteger+bInteger

' .

sub esp, 8
.Lt_0002:
mov dword ptr [ebp-4], 0
mov dword ptr [ebp-8], 1
mov eax, dword ptr [ebp-8]
add dword ptr [ebp-4], eax

Dim As Integer aInteger
Const As Integer cInteger=1
aInteger=aInteger+cInteger

' Const.

sub esp, 4
.Lt_0002:
mov dword ptr [ebp-4], 0
inc dword ptr [ebp-4]

Dim As Integer aInteger
#Define dINTEGER 1
aInteger=aInteger+dINTEGER

' #Define.

sub esp, 4
.Lt_0002:
mov dword ptr [ebp-4], 0
inc dword ptr [ebp-4]


, Asm , . , .


.
(..., ByRef As Integer), UInteger. . , ( ), , , .


: Vadim Weinberg ( 16, 2014 6:53 pm), 1 ()

Vadim Weinberg

: 18
: 2010-07-08
: 52
:

   

Re:

   15, 2014 7:52 am

, mov inc .
avatar

: 99
: 2008-08-20
: 33
:

 http://www.freebasic.su

   

Re:

  Vadim Weinberg 16, 2014 6:51 pm

zamabuvaraeu : , mov inc .

.

inc eax
add eax, 1

. .
( Pentium ) add 1 , inc. 2. , , . inc 2 .
, inc 1 , add 2 . - ( Z80?). , , .
, .
, .

P.S.

"The microarchitecture of Intel, AMD and VIA CPUs." :

INC and DEC

These instructions have a problem with partial flag access.

Always replace INC EAX with ADD EAX,1, etc.

- , add.

Vadim Weinberg

: 18
: 2010-07-08
: 52
:

   

Re:

  electrik 20, 2014 11:09 pm

, : .
, , .
, 1000000 pi, FreeBasic- .
:

:

: : : Asm mov eax, [aInt]' :
: : : Asm inc eax ' :
: : : Asm mov [aInt], eax'

:
:

: : : Asm push [aInt]' :
asm pop eax
: : : Asm inc eax ' :
asm push eax
: : : Asm pop [aInt]' :
, , . .
, , , , , .
, . 10 , , 64 . ! , , , .
, - - .
, , 14. , , . , . , .

electrik

: 391
: 2008-09-02
: 36
: , , , ,

   

Re:

   30, 2014 6:53 pm

, .
avatar

: 99
: 2008-08-20
: 33
:

 http://www.freebasic.su

   

Re:

  




   

    


FreeBasic ::  :: 

 
: