From grant at mclean.net.nz Sun Jun 8 14:45:29 2014 From: grant at mclean.net.nz (Grant McLean) Date: Mon, 09 Jun 2014 09:45:29 +1200 Subject: [Wellington-pm] Meeting tomorrow night Message-ID: <1402263929.5918.149.camel@putnam.wgtn.cat-it.co.nz> Hi Mongers The next meeting of Wellington Perl Mongers is on tomorrow evening - Tuesday June 10th: 6:00pm Tuesday 10 June 2014 Level 3, Catalyst House 150 Willis Street Wellington http://wellington.pm.org/ This month Raf Gemmail is going to talk to us about Moose. There's room for another speaker - let me know if you'd like to a slot. See you there Grant From florent.mara at nzregen.co.nz Sun Jun 8 18:46:39 2014 From: florent.mara at nzregen.co.nz (Florent Mara) Date: Mon, 9 Jun 2014 13:46:39 +1200 Subject: [Wellington-pm] Meeting tomorrow night In-Reply-To: <1402263929.5918.149.camel@putnam.wgtn.cat-it.co.nz> References: <1402263929.5918.149.camel@putnam.wgtn.cat-it.co.nz> Message-ID: Awesome! Thanks by advance Raf and I am looking forward to tomorrow. On Mon, Jun 9, 2014 at 9:45 AM, Grant McLean wrote: > Hi Mongers > > The next meeting of Wellington Perl Mongers is on tomorrow evening - > Tuesday June 10th: > > 6:00pm Tuesday 10 June 2014 > Level 3, Catalyst House > 150 Willis Street > Wellington > http://wellington.pm.org/ > > This month Raf Gemmail is going to talk to us about Moose. There's room > for another speaker - let me know if you'd like to a slot. > > See you there > Grant > > _______________________________________________ > Wellington-pm mailing list > Wellington-pm at pm.org > http://mail.pm.org/mailman/listinfo/wellington-pm > -- -------------- next part -------------- An HTML attachment was scrubbed... URL: From hugh at davenport.net.nz Tue Jun 10 21:51:30 2014 From: hugh at davenport.net.nz (Hugh Davenport) Date: Wed, 11 Jun 2014 16:51:30 +1200 Subject: [Wellington-pm] Fwd: [wellylug] [Fwd: [lca-announce] linux.conf.au 2015 opens call for presentations] Message-ID: fyi -------- Original Message -------- Subject: [wellylug] [Fwd: [lca-announce] linux.conf.au 2015 opens call for presentations] Date: 2014-06-10 21:44 From: "Steven Ellis" To: aucklug at googlegroups.com, ""NZOSS Open Discussion List"" , ""Wellington Linux Users Group"" Reply-To: Wellington Linux Users Group Please pass onto other user groups you are a member of. Lets make 2015 in Auckland amazing. ---------------------------- Original Message ---------------------------- Subject: [lca-announce] linux.conf.au 2015 opens call for presentations From: "linux.conf.au Announcements" Date: Tue, June 10, 2014 6:58 pm To: lca-announce at lists.linux.org.au -------------------------------------------------------------------------- === linux.conf.au Call For Proposals === The call for proposals for linux.conf.au 2015 is now open! The conference is a meeting place for the free and open source software communities. It will be held in Auckland at the University of Auckland Business School from Monday 12 to Friday 16 January, 2015, and provides a unique opportunity for open source developers, students, users and hackers to come together, share new ideas and collaborate. === Important Dates === * Call for Proposals opens 9 June 2014 * Call for Proposals closes 13 July 2014 * Email acceptances start September 2014 * Early bird registrations open 23 September 2014 * Conference dates: Monday 12 January to Friday 16 January, 2015 === Information on Proposals === The linux.conf.au 2015 papers committee is looking for a broad range of proposals, and will consider submissions on anything from programming and software, to desktop, mobile, gaming, userspace, community, government, space, and education. There is only one rule: *Your proposal must be related to open source* This year, the papers committee is going to be focused on open source in education as well as our usual focus on deep technical content. The conference is to a large extent what the speakers make it: if we receive heaps of excellent submissions on a topic, then it???s sure to be represented at the conference. Here???s a few ideas to get you started: * Clouds, data centers and scalability. * Community challenges; legal threats; education and outreach. * Documentation for open source projects. * HTML5; multimedia codecs. * Kernel developments; new architectures. * Open hardware; embedded systems; wearable computing. * Security; privacy; anonymity. * Networking; Software defined networking; bufferbloat; network function virtualization. * Software development; programming languages. * Sysadmin and automation. linux.conf.au is known for presentations and tutorials that are strongly technical in nature, but proposals for presentations on other aspects of free software and open culture, such as educational and cultural applications of open source, are welcome. === Code of Conduct === linux.conf.au welcomes first-time and seasoned speakers from all free and open communities: people of all ages, genders, nationalities, ethnicities, backgrounds, religions, abilities, and walks of life. We respect and encourage diversity at our conference. By agreeing to present at or attend the conference, you are agreeing to abide by the terms and conditions (http://lca2015.linux.org.au/cor/terms_and_conditions). We also expect all speakers and delegates to have read and understood our Code of Conduct (http://lca2015.linux.org.au/cor/code_of_conduct). === Format === There are three different ways that you can present your content: * Presentations * Tutorials * Mini conferences _Presentations_ Presentations are 45 minute slots that are generally presented in lecture format. These form the bulk of the available conference slots. _Tutorials_ Tutorials are 100 minutes long, and are generally presented in a classroom format. They should be interactive or hands-on in nature. Tutorials are expected to have a specific learning outcome for attendees. _Mini conferences_ Miniconfs are one or two day long sessions on a specific topic. A separate CFP form will be used to propose and select miniconfs, and is available at http://lca2015.linux.org.au/miniconf-cfp === Speaker Information === In recognition of the value that speakers bring to our conference, once a proposal is accepted a speaker is entitled to: * Free registration, which holds all of the benefits of a Professional Delegate Ticket * Exclusive tickets to the Speakers' Dinner for the speaker and their immediate family * One free family ticket to the Partners' Programme If your proposal includes more than one speaker, these additional speakers are not entitled to free registration or to any extra benefits. linux.conf.au does not and will not pay speakers to present at the conference. linux.conf.au is able to provide limited financial assistance for some speakers, for instance, where the cost of flights or accommodation might prohibit a speaker from attending. Please note, however, that there is a limited budget for travel assistance and that asking for assistance could affect your chances of acceptance. === Recording and Licensing === To increase the number of people that can view your presentation, linux.conf.au might record your talk and make it publicly available after the event. When submitting your proposal you will be asked to release materials relating to your presentation under a Creative Commons ShareAlike License. Additionally, if you are discussing software in your presentation, you must ensure the software has an appropriate open licence. All presentation material should be suitable for people aged 12 and above. All presentations are subject to Linux Australia???s code of conduct, including that they must not contain: sexual or violent imagery exclusionary language language which is not appropriate for an all-ages audience For more information, see: http://lca2015.linux.org.au/cfp === About Linux Australia === Linux Australia is the peak body for open source communities around Australia, and as such represents approximately 3500 Free and Open Source users and developers. Linux Australia supports the organisation of this international Free Software conference in a different Australasian city each year. For more information about Linux Australia see: http://www.linux.org.au/ === Papers Enquiries === For enquiries related to this CFP, or to presentations at linux.conf.au generally, contact the linux.conf.au 2015 Papers Committee by email: papers-chair at linux.org.au _______________________________________________ lca-announce mailing list lca-announce at lists.linux.org.au http://lists.linux.org.au/listinfo/lca-announce From richard at walnut.gen.nz Mon Jun 16 02:59:29 2014 From: richard at walnut.gen.nz (Richard Hector) Date: Mon, 16 Jun 2014 21:59:29 +1200 Subject: [Wellington-pm] comparison and assignment: insignificant optimisation Message-ID: <539EC001.4010503@walnut.gen.nz> Hi all, I often find it necessary to do some comparison, then do something with one of the operands. Here's a common example: sub max_length { my @list = @_; my $current_max; foreach my $item (@list) { if (length($item) > $current_max) { $current_max = length($item); } } return $current_max; } What irritates me is that the length of the string is evaluated twice. That, I admit, is probably not very expensive, but it irritates me nonetheless, and it could be worse if it's something more complicated than finding the length of a string. I know I could get round that by putting the result of length into a temporary variable, but that irritates me just by adding lines of code :-) I was wondering if there was a simpler way - maybe something like one of those action-assignment operators, like += or ||=. Any suggestions? Richard From perl at ewen.mcneill.gen.nz Mon Jun 16 03:42:37 2014 From: perl at ewen.mcneill.gen.nz (Ewen McNeill) Date: Mon, 16 Jun 2014 22:42:37 +1200 Subject: [Wellington-pm] comparison and assignment: insignificant optimisation In-Reply-To: <539EC001.4010503@walnut.gen.nz> References: <539EC001.4010503@walnut.gen.nz> Message-ID: <539ECA1D.4000208@ewen.mcneill.gen.nz> On 16/06/14 21:59, Richard Hector wrote: > I often find it necessary to do some comparison, then do something with > one of the operands. Here's a common example: > > sub max_length { [...] > > What irritates me is that the length of the string is evaluated twice. That particular one can be optimised by using map(), and further optimised by using List::Util max(): use List::Util qw(max); sub max_length { return max(map { length($_) } @_); } Although you're trading memory (array of all lengths of strings) for time (calculating the lengths twice for any longer ones) and avoiding an explicit temporary variable. (A list pre-sorted by length will be pessimal for your original algorithm; a list reverse sorted by length will be optimal, since it'll only calculate the length of the first element twice, and then the rest will be shorter so not re-calculated.) Some quick testing suggests this might work to avoid the storage requirement: use List::Util qw(max reduce); sub max_length { return reduce { max($a, length($b)) } 0, @_; } (although it also gives me warnings of $main::a and $main::b only being used once). OTOH, you're going to be calling max() a bunch more times on a long list, so function call overhead might hurt -- explicitly using the ternary operator might help, but you'd have to use a temporary variable to avoid length($b) being evaluated twice... which is the problem we started with. FWIW, in your example if the optimiser knows that length($foo) is constant for a constant input then it should be able to peephole optimise it with a temporary variable, so it's only calculated once. I couldn't quickly find out whether Perl's peephole optimiser (peep()) does that or not. I guess my point here is that it may be premature optimisation unless you have a performance problem. My concern would be readability I think, and I'd tend to use something with max() for that reason. > I was wondering if there was a simpler way - maybe something like one of > those action-assignment operators, like += or ||=. AFAICT Perl doesn't have a built in "assign if greater than" operator :-) $foo = max($foo, $bar) is about the closest you get, and even then you need to import max. Ewen From olly at survex.com Mon Jun 16 04:09:08 2014 From: olly at survex.com (Olly Betts) Date: Mon, 16 Jun 2014 12:09:08 +0100 Subject: [Wellington-pm] comparison and assignment: insignificant optimisation In-Reply-To: <539ECA1D.4000208@ewen.mcneill.gen.nz> References: <539EC001.4010503@walnut.gen.nz> <539ECA1D.4000208@ewen.mcneill.gen.nz> Message-ID: <20140616110908.GD8413@survex.com> On Mon, Jun 16, 2014 at 10:42:37PM +1200, Ewen McNeill wrote: > FWIW, in your example if the optimiser knows that length($foo) is > constant for a constant input then it should be able to peephole > optimise it with a temporary variable, so it's only calculated once. A Perl scalar holding a string knows the string's length (it doesn't do something like calling C's strlen() function each time - it can't as the string might contain zero bytes) so length($foo) just loads a value from a field in a C structure to get the length. It may need to turn the scalar into a string first, but if you call it more than once, only the first call should need to do that. > I guess my point here is that it may be premature optimisation > unless you have a performance problem. For this case, I suspect so, though Richard did say this was just an example, and he was more concerned about similar cases but with a more complex expression. Cheers, Olly From kentfredric at gmail.com Mon Jun 16 04:13:19 2014 From: kentfredric at gmail.com (Kent Fredric) Date: Mon, 16 Jun 2014 23:13:19 +1200 Subject: [Wellington-pm] comparison and assignment: insignificant optimisation In-Reply-To: <539EC001.4010503@walnut.gen.nz> References: <539EC001.4010503@walnut.gen.nz> Message-ID: You can do it with a temporary variable *without* adding lines of code. In fact, this way of doing it will reduce your lines of code =) sub max_length { my @list = @_; my $current_max; foreach my $item (@list) { next unless ( my $len = length($item) ) > $current_max; $current_max = $len; } return $current_max; } Granted you need to have a little more brain power active to parse what is going on there. -- Kent -------------- next part -------------- An HTML attachment was scrubbed... URL: From kentfredric at gmail.com Mon Jun 16 06:35:08 2014 From: kentfredric at gmail.com (Kent Fredric) Date: Tue, 17 Jun 2014 01:35:08 +1200 Subject: [Wellington-pm] comparison and assignment: insignificant optimisation In-Reply-To: <20140616110908.GD8413@survex.com> References: <539EC001.4010503@walnut.gen.nz> <539ECA1D.4000208@ewen.mcneill.gen.nz> <20140616110908.GD8413@survex.com> Message-ID: On 16 June 2014 23:09, Olly Betts wrote: > A Perl scalar holding a string knows the string's length (it doesn't do > something like calling C's strlen() function each time - it can't as the > string might contain zero bytes) so length($foo) just loads a value from > a field in a C structure to get the length. It may need to turn the > scalar into a string first, but if you call it more than once, only > the first call should need to do that. > Indeed: perl -MO=Concise -e'my $var = q[hello]; length($var)' 9 <@> leave[1 ref] vKP/REFC ->(end) 1 <0> enter ->2 2 <;> nextstate(main 1 -e:1) v:{ ->3 5 <2> sassign vKS/2 ->6 3 <$> const(PV "hello") s ->4 4 <0> padsv[$var:1,2] sRM*/LVINTRO ->5 6 <;> nextstate(main 2 -e:1) v:{ ->7 8 <1> length[t2] vK/1 ->9 7 <0> padsv[$var:1,2] s ->8 perl -MO=Concise,-exec -e'my $var = q[hello]; length($var)' 1 <0> enter 2 <;> nextstate(main 1 -e:1) v:{ 3 <$> const(PV "hello") s 4 <0> padsv[$var:1,2] sRM*/LVINTRO 5 <2> sassign vKS/2 6 <;> nextstate(main 2 -e:1) v:{ 7 <0> padsv[$var:1,2] s 8 <1> length[t2] vK/1 9 <@> leave[1 ref] vKP/REFC perl -MDevel::Peek -e'my $var = q[hello]; print Dump $var; $var .= q[world]; print Dump $var' SV = PV(0x2559d80) at 0x2579778 REFCNT = 1 FLAGS = (PADMY,POK,IsCOW,pPOK) PV = 0x257f800 "hello"\0 CUR = 5 LEN = 10 COW_REFCNT = 1 SV = PV(0x2559d80) at 0x2579778 REFCNT = 1 FLAGS = (PADMY,POK,pPOK) PV = 0x25686a0 "helloworld"\0 CUR = 10 LEN = 16 Note value of CUR length() does involve a fair amount of low-level jumping, but its more or less a plumbing route that ends up returning the value of CUR https://metacpan.org/source/RJBS/perl-5.20.0/pp.c#L2933 https://metacpan.org/source/RJBS/perl-5.20.0/sv.c#L6849 https://metacpan.org/source/RJBS/perl-5.20.0/sv.h#L1666 https://metacpan.org/source/RJBS/perl-5.20.0/sv.h#L1176 https://metacpan.org/source/RJBS/perl-5.20.0/sv.h#L469 Just the question is: Does all that cost more than creating a variable, assigning it, then re-reading it or not? That is why its better to optimise based on measured data than hypothesis :) --- use strict; use warnings; use utf8; use Benchmark qw( :all :hireswallclock ); cmpthese( -10, { '2x length' => sub { my $value = q[Hello World]; for ( 0 .. 2000 ) { my $initial = 0; if ( length($value) > $initial ) { $initial = length($value); } } }, 'tempvar' => sub { my $value = q[Hello World]; for ( 0 .. 2000 ) { my $initial = 0; if ( ( my $temp = length($value) ) > $initial ) { $initial = $temp; } } } } ); --- Rate tempvar 2x length tempvar 2323/s -- -22% 2x length 2966/s 28% -- -- Guess it wasn't worth the effort. -- Kent -------------- next part -------------- An HTML attachment was scrubbed... URL: From grant at mclean.net.nz Mon Jun 16 14:05:24 2014 From: grant at mclean.net.nz (Grant McLean) Date: Tue, 17 Jun 2014 09:05:24 +1200 Subject: [Wellington-pm] comparison and assignment: insignificant optimisation In-Reply-To: References: <539EC001.4010503@walnut.gen.nz> <539ECA1D.4000208@ewen.mcneill.gen.nz> <20140616110908.GD8413@survex.com> Message-ID: <1402952724.5979.29.camel@putnam.wgtn.cat-it.co.nz> On Tue, 2014-06-17 at 01:35 +1200, Kent Fredric wrote: > length() does involve a fair amount of low-level jumping, but its more > or less a plumbing route that ends up returning the value of CUR Not quite so rosy for UTF8 strings: https://metacpan.org/source/RJBS/perl-5.20.0/utf8.c#L1132 But yeah still not worth worth worrying about unless profiling shows it's a problem. Cheers Grant From douglas at halo.gen.nz Mon Jun 16 15:49:18 2014 From: douglas at halo.gen.nz (Douglas Bagnall) Date: Tue, 17 Jun 2014 10:49:18 +1200 Subject: [Wellington-pm] comparison and assignment: insignificant optimisation In-Reply-To: <20140616110908.GD8413@survex.com> References: <539EC001.4010503@walnut.gen.nz> <539ECA1D.4000208@ewen.mcneill.gen.nz> <20140616110908.GD8413@survex.com> Message-ID: <539F746E.5050703@halo.gen.nz> On 16/06/14 23:09, Olly Betts wrote: > A Perl scalar holding a string knows the string's length (it doesn't do > something like calling C's strlen() function each time - it can't as the > string might contain zero bytes) so length($foo) just loads a value from > a field in a C structure to get the length. It may need to turn the > scalar into a string first, but if you call it more than once, only > the first call should need to do that. This is also how it works Python, but there the temporary variable would probably[1] still be quicker than a double function call, due to the way name resolution works. At compile time Python knows there is a call to a something called len, but it doesn't know whether that something is in local scope, a containing scope, the module global scope, or built in to the interpreter. There are any number of ways something can unexpectedly turn up in one of these namespaces, so the interpreter has to look it up every time -- in exactly the wrong order for finding the builtin len(). Which means that instantaneously accessible length in the C struct is protected by about 4 hash look-ups, while the local variable would be found in one hash look-up. But Perl is different, right? Functions have their own scope hierarchy and all that, so can the compiler know you mean the built-in length? I am afraid I can't tell from Kent's disassembly. cheers, Douglas [1] In the spirit of this thread, I offer no empirical results. Besides which, we are optimising for Richard Hector non-irritation, and I have no local copy.