multithreading


Perl threads get iterations speed


I have some code:
for my $t (1..$threads) {
push #threads, threads->create(\&action_, $t);
}
for my $t (#threads) {
$t->join();
}
sub action_ {
while (#sites) {
my $url = shift #sites;
for my $data1 (#data) {
for my $data2 (#data2) {
something($url, $data1, $data2);
}
}
}
}
How to get speed(number of calls method "something") per second(or minute)?
Thanks.
If you're looking to do it yourself quickly, a gross estimate can be obtained like so:
use List::Util qw(sum);
use feature qw(say);
...
my $t0 = time(); # See also Time::HiRes
threads->create(\&action_) for 1 .. $nthreads;
my $nsomething = sum map { $_->join } threads->list();
my $elapsed = time() - $t0;
say "Among $nthreads threads we called something() ",
($nsomething/$elapsed),
" times per second";
sub action_ {
my $n;
while (...) { ... something(); $n++; ... }
return $n;
}
If that's not fine enough, you might have each call to something() push the time it was invoked on to a threads::shared::share()d array — or in a thread-local array that you collect after the join(), or printed to a mutex-protected filehandle or whatever. Then you can do whatever you like with the time series you've generated.
Perl has a number of benchmarking modules in CPAN. Take a look at: http://perldoc.perl.org/Benchmark.html
This explains it well; basically the code you want to benchmark is wrapped up in a subroutine and you're free to count or compare different routines.
The method I use most commonly is under the heading 'Methods' and 'New'.

Related Links

QT - C++ / Running a worker thread within idle phase of a periodic event
Technical Differences Between Service and Web Workers
Elasticsearch 5.2 unit tests
Django plus Celery/RabbitMQ with threading for C socket module
How to stop threads, once there is no more data in Chan to process?
How to wrap multi-threaded callbacks in Rust?
Spawn Expect from a perl thread
How can I return a JoinHandle from a function?
Forcing a message loop to yield
Weird callstack leading up to CreateRemoteThread
Does a process stop all his threads while processing a signal? [duplicate]
What's a Thead in FOSMessageBundle
FreeRTOS Mutex multiple task with same priority
Multiple Clients and Timeout on sd-bus service
How to interface between managed class and 'normal' software
Threading in .NET Framework 4.6 vs 4.0

Categories

HOME
netsuite
kde
nullpointerexception
google-oauth
c#-2.0
icloud
serverspec
django-imagekit
mouse
facebook-php-sdk
reveal.js
midi
modelica
google-cloud-spanner
decomposition
clearcase-ucm
saxon
transformation
evopdf
samoa
emulator
immutable.js
visjs
paging
functional-testing
sqlcipher
pepper
dynamic-featured-image
spring-mybatis
strncpy
saas
tinymce-4
fabric8
google-qpx-express-api
kendo-ui-grid
avcapturesession
android-ble
plsql-psp
lto
bootstrapper
hp-ux
avro4s
isbn
midl
dds
hls.js
jxcore
google-perftools
android-cursor
mako
chord-diagram
or-tools
color-picker
trash
asp.net-4.5
etsy
multiple-regression
nsviewcontroller
sdf
pagerank
fouc
browser-bugs
oberon
c++03
csquery
android-nested-fragment
onactivityresult
starcluster
funcunit
htmlcleaner
didselectrowatindexpath
imdbpy
file-locking
ember-app-kit
drools-planner
labwindows
jspinclude
uiviewanimation-curve
asyncfileupload
whoosh
blackberry-playbook
site.master
sudzc
asp.net-mvc-areas
kdbg
virtual-functions
premature-optimization
lzh

Resources

Database Users
RDBMS discuss
Database Dev&Adm
javascript
java
csharp
php
android
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App