Page 1 of 1
mod_harbour benchmark utility using CURL
Posted: Tue Feb 18, 2020 11:13 am
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
Re: mod_harbour benchmark utility using CURL
Posted: Tue Feb 18, 2020 11:28 am
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