mod_harbour benchmark utility using CURL

mod_harbour is an Apache module that allows to run PRGs directly on the web !!!
Post Reply
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

mod_harbour benchmark utility using CURL

Post by Antonio Linares »

Code: Select all

#include "/home/user/harbour/contrib/hbcurl/hbcurl.ch"

function Main()

   local n

   for n = 1 to 10
     hb_threadStart( @ReadWeb() )
   next

   hb_threadWaitForAll()
   InKey( 1 )

return nil   

function ReadWeb()
    
    local hCurl, cBuffer := ""
    local cUrl  := "http://www.modharbour.org/modharbour_samples/info.prg"

    curl_global_init()  
    
    if ! empty( hCurl := curl_easy_init() )
        curl_easy_setopt( hCurl, HB_CURLOPT_URL, cUrl )
        curl_easy_setopt( hCurl, HB_CURLOPT_DL_BUFF_SETUP )

        if curl_easy_perform( hCurl ) == 0
           uValue = curl_easy_dl_buff_get( hCurl )
           ? 'Thread: ', hb_threadId(), 'Get: ', Len( uValue )
        endif
    endif
    
    curl_global_cleanup()

return nil
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Re: mod_harbour benchmark utility using CURL

Post by Antonio Linares »

Another version by Carles:

Code: Select all

function Main()

   local n
   local aThreads := {}

   Aadd( aThreads, hb_threadStart( @Slow() ) )
   
   for n = 1 to 10
      Aadd( aThreads, hb_threadStart( @ReadWeb() ) )
   next
   
   nThreads := len( aThreads )
   
   while ( j := hb_threadWait( aThreads, 0.1, .T.) ) <> nThreads
        ? 'Executed => ' , j
   end
   
   ? 'Executed All => ', nThreads
   
   hb_threadWaitForAll()
   InKey( 1 )  

return nil   

function Slow()
    inkey(3)
    ? 'Thread: ', hb_threadId(), 'Slow Done'
retu nil

function ReadWeb()
    
    local hCurl, cBuffer := ""
    local cUrl  := "http://www.modharbour.org/modharbour_samples/info.prg"

    curl_global_init()  
    
    if ! empty( hCurl := curl_easy_init() )
        curl_easy_setopt( hCurl, HB_CURLOPT_URL, cUrl )
        curl_easy_setopt( hCurl, HB_CURLOPT_DL_BUFF_SETUP )

        if curl_easy_perform( hCurl ) == 0
            uValue := curl_easy_dl_buff_get( hCurl )
            ? 'Thread: ', hb_threadId(), 'Get: ' , len( uValue)
            
        endif
    endif
    
    curl_global_cleanup()

return nil  
regards, saludos

Antonio Linares
www.fivetechsoft.com
Post Reply