XML::LibXML で属性を取り出すときのベンチマーク
XML::LibXML を使って、XML の属性を取り出すときに findvalue メソッドで XPath を使うのと XML::LibXML::Element のメソッド getAttribute を使うのとどちらが早いのかベンチマークしてみました。
Benchmark: timing 10000 iterations of accessor, xpath... accessor: 0 wallclock secs ( 0.05 usr + 0.00 sys = 0.05 CPU) @ 200000.00/s (n=10000) (warning: too few iterations for a reliable count) xpath: 1 wallclock secs ( 0.55 usr + 0.00 sys = 0.55 CPU) @ 18181.82/s (n=10000)
XPath の方が遅いのか。。。XPathエンジンとか重たいのかな?
以下がコードです。
#!/usr/local/bin/perl use strict; use warnings; use XML::LibXML; use Perl6::Say; use Benchmark; my $xp = XML::LibXML->new; my $doc = $xp->parse_string(<<"XML"); <?xml version="1.0"?> <doc attr="please"> please ignore.this is a test. </doc> XML my $xml = $doc->documentElement; timethese (10000, { 'accessor' => sub { $xml->getAttribute('attr') }, 'xpath' => sub { $xml->findvalue('@attr') }, });
追記
さらに、Devel::Profile を用いて、上記の timethese の中の accessor と xpath のそれぞれ片方だけを実行した結果の上位10位です。(上記のコードを baz.pl として保存して、perl -d:Profile baz.pl と実行)
'accessor'のみ実行(#'xpath'の行をコメントアウト)
time elapsed (wall): 0.7500
time running program: 0.5730 (76.40%)
time profiling (est.): 0.1770 (23.60%)
number of calls: 41183%Time Sec. #calls sec/call F name
34.91 0.2000 20000 0.000010 :.../Perl/5.8.6/Benchmark.pm:651
18.27 0.1047 10000 0.000010 XML::LibXML::Element::getAttribute
10.43 0.0598 1 0.059758 :.../Perl/5.8.6/Benchmark.pm:675
10.41 0.0597 10000 0.000006 XML::LibXML::Element::_getAttribute
10.30 0.0590 1 0.059044 :.../Perl/5.8.6/Benchmark.pm:682
3.16 0.0181 1 0.018114 :baz.pl:6
1.23 0.0071 383 0.000018 Benchmark::new
1.17 0.0067 0 0.006728 *
1.15 0.0066 1 0.006588 :baz.pl:9
1.10 0.0063 1 0.006291 :baz.pl:8
'xpath'のみ実行(#'accessor'の行をコメントアウト)
time elapsed (wall): 2.2250
time running program: 1.7546 (78.86%)
time profiling (est.): 0.4705 (21.14%)
number of calls: 111103%Time Sec. #calls sec/call F name
21.90 0.3842 10000 0.000038 XML::LibXML::Node::_find
17.64 0.3096 10000 0.000031 XML::LibXML::Node::findvalue
11.83 0.2076 10000 0.000021 XML::LibXML::NodeList::to_literal
11.63 0.2041 20000 0.000010 :.../Perl/5.8.6/Benchmark.pm:651
11.26 0.1976 10000 0.000020 XML::LibXML::Node::find
3.90 0.0684 10000 0.000007 XML::LibXML::Node::string_value
3.56 0.0625 1 0.062548 :.../Perl/5.8.6/Benchmark.pm:682
3.44 0.0604 1 0.060442 :.../Perl/5.8.6/Benchmark.pm:675
3.36 0.0590 10000 0.000006 XML::LibXML::Literal::new
3.23 0.0566 10000 0.000006 XML::LibXML::NodeList::new
Awesome things here. I am very happy to see your post. Thanks so much and I am looking forward to contact you. Will you kindly drop me a e-mail?
Posted by: garcinia cambogia where to buy | 12 November 2013 at 05:13 AM
I do not leave a leave a response, but I read a ton of responses on blog.comewalk.com : XML::LibXML で属性を取り出すときのベンチマーク. I do have a couple of questions for you if you don't mind. Could it be just me or do a few of these remarks appear like they are left by brain dead visitors? :-P And, if you are writing at additional places, I'd like to follow anything fresh you have to post. Could you list of all of your social community pages like your Facebook page, twitter feed, or linkedin profile?
Posted by: garcinia cambogia extract where can i buy it | 14 November 2013 at 02:04 AM
Hello! I simply wish to give you a big thumbs up for the excellent info you've got right here on this post. I will be coming back to your website for more soon.
Posted by: garcinia cambogia reviews | 27 November 2013 at 04:17 PM
Hi to every one, because I am in fact keen of reading this web site's post to be updated on a regular basis. It consists of fastidious data.
Posted by: http://www.youtube.com/watch?v=_FNb0a1ckG4 | 01 December 2013 at 03:28 AM
Great post. I was checking constantly this blog and I am impressed! Very helpful information specifically the last part :) I care for such info a lot. I was looking for this particular information for a very long time. Thank you and good luck.
Posted by: where can you buy garcinia cambogia | 04 December 2013 at 02:30 PM
Thanks for sharing your thoughts. I really appreciate your efforts and I will be waiting for your next post thanks once again.
Posted by: garcinia cambogia | 12 December 2013 at 05:32 AM
It's an awesome article designed for all the internet visitors; they will get benefit from it I am sure.
Posted by: garcinia cambogia extract reviews | 16 December 2013 at 09:46 AM
Hi, I do believe this is a great website. I stumbledupon it ;) I will revisit once again since I book marked it. Money and freedom is the best way to change, may you be rich and continue to help other people.
Posted by: weight loss pills review | 16 December 2013 at 03:01 PM
This is really attention-grabbing, You're an overly skilled blogger. I've joined your rss feed and stay up for in the hunt for more of your wonderful post. Additionally, I have shared your website in my social networks
Posted by: fashion clothing cotton | 19 October 2014 at 04:19 PM
I was able to find good advice from your articles.
Posted by: charger samsung graphic faceplate | 06 November 2014 at 02:37 AM
I've been exploring for a little bit for any high-quality articles or weblog posts in this sort of house . Exploring in Yahoo I at last stumbled upon this web site. Reading this information So i am happy to convey that I've an incredibly excellent uncanny feeling I found out just what I needed. I such a lot certainly will make certain to do not omit this site and give it a glance regularly.
Posted by: chromo inc mesh stylus | 08 November 2014 at 08:40 AM
With havin so much written content do you ever run into any issues of plagorism or copyright violation? My blog has a lot of completely unique content I've either written myself or outsourced but it seems a lot of it is popping it up all over the web without my permission. Do you know any methods to help reduce content from being stolen? I'd genuinely appreciate it.
Posted by: Garcinia cambogia miracle Reviews | 14 November 2014 at 09:04 AM
Hello, I log on to your blog daily. Your humoristic style is awesome, keep up the good work!
Posted by: nutratone plus | 07 December 2014 at 06:37 PM
I have been exploring for a bit for any high-quality articles or weblog posts in this sort of area . Exploring in Yahoo I at last stumbled upon this site. Studying this information So i'm satisfied to convey that I have a very good uncanny feeling I found out exactly what I needed. I so much indubitably will make certain to do not omit this website and give it a look regularly.
Posted by: sport x small | 14 December 2014 at 12:41 AM
Howdy! This is my first visit to your blog! We are a group of volunteers and starting a new initiative in a community in the same niche. Your blog provided us useful information to work on. You have done a marvellous job!
Posted by: charging universal charger motorola | 19 December 2014 at 03:22 AM
The quantity of the money and also the repayment tenure will probably be decided depending about the income of the application, age, stability of occupation, and current liabilities if any super real now sometimes all lenders will supply you with this particular type of loan.
Posted by: super real | 02 January 2015 at 09:05 PM
Hi, I think your site might be having browser compatibility issues. When I look at your blog site in Safari, it looks fine but when opening in Internet Explorer, it has some overlapping. I just wanted to give you a quick heads up! Other then that, very good blog!
Posted by: http://www.youtube.com/ | 05 January 2015 at 11:43 AM
Hi to all, it's genuinely a pleasant for me to pay a quick visit this website, it contains precious Information.
Posted by: canadian pharmacy online | 08 January 2015 at 09:21 PM