increase aplication speed

Post Reply
User avatar
fafi
Posts: 169
Joined: Mon Feb 25, 2008 2:42 am

increase aplication speed

Post by fafi »

Hi All

To test : call it every where..

Waiting for feed back..

Thanks
Best Regards
Fafi

Code: Select all

FUNCTION MemoryFlush() 
    
local nResult
local MemorySize := 1024*1024*1024
    
if nResult := SetProcess( GetCurrentProcess(), MemorySize, MemorySize*2 )   <= 0
     MemorySize := 512*1024*1024
     if nResult := SetProcess( GetCurrentProcess(), MemorySize, MemorySize*2 )  <= 0    
         MemorySize := 64*1024*1024
         if nResult := SetProcess( GetCurrentProcess(), MemorySize, MemorySize*2 )  <= 0
              MemorySize := 32*1024*1024
              if nResult := SetProcess( GetCurrentProcess(), MemorySize, MemorySize*2 ) <= 0
                 nResult := SetProcess( GetCurrentProcess(), -1, -1 )   <= 0
              endif     
         endif  
     endif
endif   

SysRefresh()
    
RETURN nResult

DLL32 Function SetProcess( ;
   hWnd As LONG, nMinWorkingSpace As LONG, nMaxWorkingSpace As LONG ) ;
   As LONG PASCAL From "SetProcessWorkingSetSize" Lib "Kernel32.dll"

DLL32 Function GetCurrentProcess() ;
   As LONG PASCAL From "GetCurrentProcess" Lib "Kernel32.dll"
 
User avatar
MarcoBoschi
Posts: 925
Joined: Thu Nov 17, 2005 11:08 am
Location: Padova - Italy
Contact:

Re: increase aplication speed

Post by MarcoBoschi »

Code: Select all

#include "fivewin.ch"
ANNOUNCE RDDSYS

FUNCTION MAIN()
LOCAL nInizio := SECONDS()
LOCAL nConta := 0
USE deb
GO TOP

DO WHILE !EOF()
   memoryflush()
   SKIP
   nConta ++
ENDDO

? SECONDS() - nInizio   , nConta

RETURN NIL

INIT PROCEDURE RddInit
REQUEST DBFFPT
REQUEST DBFCDX
rddSetDefault( "DBFCDX" )


FUNCTION MemoryFlush()

local nResult
local MemorySize := 1024*1024*1024

if nResult := SetProcess( GetCurrentProcess(), MemorySize, MemorySize*2 )   <= 0
     MemorySize := 512*1024*1024
     if nResult := SetProcess( GetCurrentProcess(), MemorySize, MemorySize*2 )  <= 0
         MemorySize := 64*1024*1024
         if nResult := SetProcess( GetCurrentProcess(), MemorySize, MemorySize*2 )  <= 0
              MemorySize := 32*1024*1024
              if nResult := SetProcess( GetCurrentProcess(), MemorySize, MemorySize*2 ) <= 0
                 nResult := SetProcess( GetCurrentProcess(), -1, -1 )   <= 0
              endif
         endif
     endif
endif

SysRefresh()

RETURN nResult

DLL32 Function SetProcess( ;
   hWnd As LONG, nMinWorkingSpace As LONG, nMaxWorkingSpace As LONG ) ;
   As LONG PASCAL From "SetProcessWorkingSetSize" Lib "Kernel32.dll"

DLL32 Function GetCurrentProcess() ;
   As LONG PASCAL From "GetCurrentProcess" Lib "Kernel32.dll"
 
I do not see any differences
I also put this function in a big app after an ACTIVATE DIALOGbut I do not see difference at all!
Could you post a sample code to evaulate this?

King regards

marco
Marco Boschi
info@marcoboschi.it
User avatar
fafi
Posts: 169
Joined: Mon Feb 25, 2008 2:42 am

Re: increase aplication speed

Post by fafi »

Mr. Marco, thanks for the test...

it's work when you have big size databases more than 50000 records

I'm sorry this my Indonesian language , look at the remarks

Code: Select all

function HitungStock()  // <-- final stock count for drug expiration dates
   
 local oDlgStock,nBanyak := obat->(lastrec()), nPos := 0
 
 MemoryFlush()
 

 define dialog oDlgStock from 1,1 to 40,350 pixel style nOR( WS_CAPTION ) title "Menghitung Kartu Stock"
 
 @ 2, 2 PROGRESS oPrg;
           SIZE 170, 15 of oDlgStock pixel
 
 activate dialog oDlgStock centered nowait
 
           nBanyak := edaw->(lastrec())
              
           oPrg:SetPos( 0 )   
           oPrg:SetRange( 0, nBanyak  )   
           edaw->(ordScope(0,nil))
           edaw->(ordScope(1,nil))      
           edaw->(dbGotop())
           
           do while !edaw->(eof())
              oPrg:SetPos( ++nPos )
              oPrg:Refresh()   
              if empty(edaw->tglawal)
                  edaw->(dbDelete())
              endif   
              edaw->(dbSkip())
           enddo
           
 
 nBanyak := obat->(lastrec())   
 oPrg:SetPos( 0 )

 oPrg:SetRange( 0, nBanyak  )  //  <--  nBanyak more than  50000 records 
       
 nPos := 0
    
 obat->(dbGotop())
 do while !obat->(eof())   // <--   more than  50000 records 
 
           MemoryFlush()
           SysRefresh()
                       
           oPrg:SetPos( ++nPos )
           oPrg:Refresh()   
              
           edaw->(ordScope(0,nil))
           edaw->(ordScope(1,nil))      
               
           edaw->(ordSetFocus("kode"))
            
           edaw->(ordScope(0,obat->kode))
           edaw->(ordScope(1,obat->kode))
           edaw->(dbGotop())
           
           dbSelectArea("fifom") 
           zap   
           
           dbSelectArea("fifok")
           zap   
           
           do while !edaw->(eof()) //  <--  more than  50000 records  <-- final stock count for drug expiration dates
              
                        if edaw->sts == "001" .or. edaw->sts == "002" .or. edaw->sts == "004"   // barang masuk
                            if !empty(edaw->tgled)
                               fifom->(dbAppend())
                               fifom->kode     := edaw->kode        
                               fifom->qty      := edaw->qty   
                               fifom->keluar   := 0
                               fifom->sisa     := edaw->qty
                               fifom->nama     := edaw->nama
                               fifom->satuan   := edaw->satuan
                               fifom->harga    := edaw->harga 
                               fifom->tgled    := edaw->tgled 
                               fifom->cnobat   := edaw->cnobat
                           endif
                        endif
                        
                        if edaw->sts == "003" .or. edaw->sts == "005"  // barang keluar
                            fifok->(dbAppend())
                            fifok->kode     := edaw->kode        
                            fifok->qty      := edaw->qty   
                            fifok->keluar   := edaw->keluar
                            fifok->sisa     := edaw->sisa  
                            fifok->harga    := edaw->harga 
                            fifok->tglawal  := edaw->tglawal
                       endif         
                     
              edaw->(dbSkip())
           enddo
           
           fifok->(dbGotop())
           do while !fifok->(eof())
              nQty := fifok->qty
              fifom->(dbGotop())
              do while !fifom->(eof())
           
                 if fifom->sisa >= nQty
                      fifom->keluar += nQty
                      fifom->sisa  := fifom->qty - fifom->keluar
                      exit
                 else
                      fifom->keluar += fifom->sisa
                      nQty -= fifom->sisa
                      fifom->sisa  := 0
                 endif   
                 fifom->(dbSkip())
              enddo            
              fifok->(dbSkip())
           enddo
           
           fifom->(dbGotop())
           do while !fifom->(eof())
              if fifom->sisa # 0
                  edsisa->(dbAppend())
                         edsisa->kode     := fifom->kode        
                         edsisa->qty      := fifom->qty   
                         edsisa->keluar   := fifom->keluar
                         edsisa->sisa     := fifom->sisa
                         edsisa->nama     := fifom->nama
                         edsisa->satuan   := fifom->satuan
                         edsisa->harga    := fifom->harga 
                         edsisa->jumlah   := fifom->harga * fifom->jumlah
                         edsisa->tgled    := fifom->tgled 
                         edsisa->cnobat   := fifom->cnobat
                               
                         obat->(ordSetFocus("kode"))
                         obat->(dbGotop())
                         if obat->(dbSeek(fifom->kode))
                            edsisa->kdjenis  := obat->kdjenis
                              edsisa->jenis    := obat->jenis   
                             edsisa->kdkel    := obat->kdkel
                            edsisa->ktkel    := obat->ktkel   
                 endif   
              endif   
              fifom->(dbSkip())
           enddo
           
           
 
          nAwal := nMasuk := nKeluar := 0  
          edaw->(dbGotop())
          do while !edaw->(eof())
             if edaw->sts == "001"
                 nAwal += edaw->qty
           endif   
           
             if edaw->sts == "002" .or. edaw->sts == "004"
                 nMasuk += edaw->qty
             endif   
           
           if edaw->sts == "003" .or. edaw->sts == "005"
                 nKeluar += edaw->qty
             endif   
             
             edaw->(dbSkip())
          enddo   
          
          if obat->(rlock())
             obat->awal   := nAwal
             obat->masuk  := nMasuk
             obat->keluar := nKeluar
             obat->sisa   := (nAwal + nMasuk) - nKeluar           
          endif   
          obat->(dbUnlock())
          obat->(dbSkip())
 
 enddo
 
 MemoryFlush()
 
 oDlgStock:End()
 
return nil
 
That's all
Regards
Fafi
User avatar
MarcoBoschi
Posts: 925
Joined: Thu Nov 17, 2005 11:08 am
Location: Padova - Italy
Contact:

Re: increase aplication speed

Post by MarcoBoschi »

Ok i'll test it
marco
Marco Boschi
info@marcoboschi.it
User avatar
Carles
Posts: 937
Joined: Fri Feb 10, 2006 2:34 pm
Location: Barcelona
Contact:

Re: increase aplication speed

Post by Carles »

fafi,

I think this code have a mistake. If u want increase speed u can't execute 50000 times refresh progress bar. I advise you to define progress bar up 100. Then u need create one var to control every time that u want refresh progress bar f.e

oPrg:SetRange( 0, 100 )
nEvery := Int( nBanyak / 100 )

Reset a counter

nLapsus := 0

And finally into loop to control it.

while ....

nLapsus++

if nLapsus > nEvery
oPrg:SetPos( ++nPos )
nLapsus := 0
endif

end

oPrg:SetPos( 100 )
Salutacions, saludos, regards

"...programar es fácil, hacer programas es difícil..."

https://modharbour.app
https://modharbour.app/compass
https://forum.modharbour.app
User avatar
fafi
Posts: 169
Joined: Mon Feb 25, 2008 2:42 am

Re: increase aplication speed

Post by fafi »

Mr. Charles..
Thanks

Regards
Fafi
User avatar
MarcoBoschi
Posts: 925
Joined: Thu Nov 17, 2005 11:08 am
Location: Padova - Italy
Contact:

Re: increase aplication speed

Post by MarcoBoschi »

fafi,
i've tested it at work in a lan.
1,5 million records
If I call your function 116 seconds
If I don't call your function 24 seconds

probably I don't understand how to use it

best regards

marco

Code: Select all

#include "fivewin.ch"
ANNOUNCE RDDSYS

FUNCTION MAIN()
LOCAL nInizio := SECONDS()
LOCAL nConta := 0
LOCAL lCall

SET DELETED ON
SET EXCLUSIVE OFF
lCall := MsgYesNo( "Call the function?" )
USE parts
GO TOP

DO WHILE !EOF()
   IF lCall
      memoryflush()
      sysrefresh()
   ENDIF
   SKIP
   nConta ++
ENDDO

? SECONDS() - nInizio   , nConta

RETURN NIL

INIT PROCEDURE RddInit
REQUEST DBFFPT
REQUEST DBFCDX
rddSetDefault( "DBFCDX" )


FUNCTION MemoryFlush()

local nResult
local MemorySize := 1024*1024*1024

if nResult := SetProcess( GetCurrentProcess(), MemorySize, MemorySize*2 )   <= 0
     MemorySize := 512*1024*1024
     if nResult := SetProcess( GetCurrentProcess(), MemorySize, MemorySize*2 )  <= 0
         MemorySize := 64*1024*1024
         if nResult := SetProcess( GetCurrentProcess(), MemorySize, MemorySize*2 )  <= 0
              MemorySize := 32*1024*1024
              if nResult := SetProcess( GetCurrentProcess(), MemorySize, MemorySize*2 ) <= 0
                 nResult := SetProcess( GetCurrentProcess(), -1, -1 )   <= 0
              endif
         endif
     endif
endif

SysRefresh()

RETURN nResult

DLL32 Function SetProcess( ;
   hWnd As LONG, nMinWorkingSpace As LONG, nMaxWorkingSpace As LONG ) ;
   As LONG PASCAL From "SetProcessWorkingSetSize" Lib "Kernel32.dll"

DLL32 Function GetCurrentProcess() ;
   As LONG PASCAL From "GetCurrentProcess" Lib "Kernel32.dll"
 
Marco Boschi
info@marcoboschi.it
Post Reply