Procedure Overhead

Everything else that doesn't fall into one of the other PB categories.
Dreglor
Enthusiast
Enthusiast
Posts: 759
Joined: Sat Aug 02, 2003 11:22 pm
Location: OR, USA

Procedure Overhead

Post by Dreglor »

why is there so much overhead with procedure calls is there something that pb does that just kills speed?

Procedure calls are speedy by them selfs but add them up in a for/while loop and they bring your program to a halt...
~Dreglor
traumatic
PureBasic Expert
PureBasic Expert
Posts: 1661
Joined: Sun Apr 27, 2003 4:41 pm
Location: Germany
Contact:

Re: Procedure Overhead

Post by traumatic »

Could you please explain what you mean by "overhead" and "brings program to halt" ?

Code: Select all

Procedure doSomething(var.l)
  ProcedureReturn var.l*2
EndProcedure

For i=0 To 99
  doSomething(i)
Next
compiles to

Code: Select all

_Procedure0:
  PUSH   ebx
  MOV    ebx,dword [esp+8]
  ADD    ebx,ebx
  MOV    eax,ebx
  JMP   _EndProcedure1
  XOR    eax,eax
_EndProcedure1:
  POP    ebx
  RET    4


  MOV    dword [v_i],0
_For1:
  MOV    eax,99
  CMP    eax,dword [v_i]
  JL    _Next2

  PUSH   dword [v_i]
  CALL  _Procedure0

_NextContinue2:
  INC    dword [v_i]
  JMP   _For1
_Next2:
Can't see much overhead there.

Do you have any specific examples in which ASM generation fails or something?
Good programmers don't comment their code. It was hard to write, should be hard to read.
Fred
Administrator
Administrator
Posts: 18351
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Post by Fred »

May be there is a memory leak in the procedure, which could fill the memory and halt the program ?
Post Reply