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

What does threadsafe mean?
Threads on WindowsXP
Reading log from Log4Net generated by multiple threads
Heavy weight and light weight thread
What operations are thread-safe on std::map?
Analyzing output of !threadpool and !threads in windbg
Copying files which the main thread adds to a stringlist using a thread
what is the difference between synchronous apis and asynchronous apis?
How to define threadsafe?
Is the go map structure thread-safe?
What to use to wait on a indeterminate number of tasks?
TcpClient and StreamReader blocks on Read
Seeking help with a MT design pattern
Mutithreading thread control
Multithreading in .NET 4.0 and performance
How to parallelize file reading and writing

Categories

HOME
xamarin
wso2
debugging
image-processing
isabelle
include
hashmap
filtering
infragistics
rubygems
youtube-api-v3
frameworks
gps
alpha
fingerprint
esper
amazon-cloudformation
handsontable
etl
alignment
clojurescript
apache-metamodel
normalizr
centos6.5
facet
xacml
gsoap
lightswitch-2013
fabric8
ecto
avcapturesession
http-referer
wpf-controls
wixsharp
gesture
starteam
objectlistview
user-controls
dism
eigenvalue
gpx
acoustics
s
.net-4.6.2
executenonquery
long-polling
jsch
outlook-2013
kbuild
mako
migradoc
root-framework
parallel-data-warehouse
android-textview
slicknav
bonobo
underscore.js-templating
django-debug-toolbar
holder.js
angstrom-linux
ubuntu-10.04
qcustomplot
whois
dataview
ipconfig
freelancer.com-api
t4mvc
cannon.js
sframe
graph-drawing
unity3d-gui
sonarqube5.1.2
truevault
kineticjs
camanjs
tt-news
android-nested-fragment
codeigniter-routing
xojo
dml
viadeo
page-layout
ccss
jsctypes
commoncrypto
dexterity
runtime.exec
padarn
plasma
nsnetservice
funscript
regsvr32
windows-phone-7.1.1
netbeans-6.9
mercurial-server
gnu-prolog
data-loss
xmlspy
lpeg
subviews
paster
dmx512
icanhaz.js
meego
procedural-music
caching-application-block
uiq3

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App