<p>I want to know what exactly is the sequence of calls that occurs when a getter/setter created through Class::MethodMaker is called?</p>

<p>How much costlier are getter/setters defined by MethodMaker than the native ones (overwritten in the module)?</p>

[{'answer_id': 62269, 'author': 'Leon Timmermans', 'author_id': 4727, 'author_profile': 'https://Stackoverflow.com/users/4727', 'pm_score': 0, 'selected': False, 'text': "<p>The real question is: does it matter?</p>\n\n<p>It's yet another accessors generating module. These modules all have a speed/functionality trade-off. Just pick one that offers everything you need. It's not like accessors are likely to become a bottleneck in your application.</p>\n"}, {'answer_id': 62293, 'author': 'Jagmal', 'author_id': 4406, 'author_profile': 'https://Stackoverflow.com/users/4406', 'pm_score': 0, 'selected': False, 'text': '<p>@Leon Timmermans</p>\n\n<p>I am aware of the fact that there is some speed/functionality trade off but want to get idea of how good/bad is it? And much better, if I can get specific of the implementations so that its easier to decide.</p>\n'}, {'answer_id': 62311, 'author': 'David Precious', 'author_id': 4040, 'author_profile': 'https://Stackoverflow.com/users/4040', 'pm_score': 1, 'selected': False, 'text': '<p>This is exactly what debugging tools are for :)</p>\n\n<p>Have a look at the <a href="http://perldoc.perl.org/perldebug.html" rel="nofollow noreferrer">perldebug</a> docs, particularly the section on profiling.</p>\n\n<p>In particular, running your script with perl -dDProf filename.pl will generate a tt.out file which the dprofpp tool (distributed with Perl) can produce a report from.</p>\n\n<p>I used the following simple test script:</p>\n\n<pre>\n#!/usr/bin/perl\n\npackage Foo;\nuse strict;\nuse Class::MethodMaker [ scalar => [\'bar\'], new => [\'new\'] ];\n\npackage main;\nuse strict;\n\nmy $foo = new Foo;\n$foo->bar(\'baz\');\nprint $foo->bar . "\\n";\n</pre>\n\n<p>Running it with perl -d:DProf methodmakertest.pl and then using dprofpp on the output gave:</p>\n\n<pre>\n[davidp@supernova:~/tmp]$ dprofpp tmon.out\nClass::MethodMaker::scalar::scal0000 has 1 unstacked calls in outer\nClass::MethodMaker::Engine::new has 1 unstacked calls in outer\nAutoLoader::AUTOLOAD has -2 unstacked calls in outer\nTotal Elapsed Time =  0.08894 Seconds\n  User+System Time =  0.07894 Seconds\nExclusive Times\n%Time ExclSec CumulS #Calls sec/call Csec/c  Name\n 25.3   0.020  0.020      4   0.0050 0.0050  Class::MethodMaker::Constants::BEG\n                                             IN\n 25.3   0.020  0.029     12   0.0017 0.0025  Class::MethodMaker::Engine::BEGIN\n 12.6   0.010  0.010      1   0.0100 0.0100  DynaLoader::dl_load_file\n 12.6   0.010  0.010      2   0.0050 0.0050  AutoLoader::AUTOLOAD\n 12.6   0.010  0.010     14   0.0007 0.0007  Class::MethodMaker::V1Compat::reph\n                                             rase_prefix_option\n 0.00   0.000  0.000      1   0.0000 0.0000  Class::MethodMaker::scalar::scal00\n                                             00\n 0.00   0.000  0.000      1   0.0000 0.0000  Class::MethodMaker::Engine::new\n 0.00       - -0.000      1        -      -  DynaLoader::dl_undef_symbols\n 0.00       - -0.000      1        -      -  Class::MethodMaker::bootstrap\n 0.00       - -0.000      1        -      -  warnings::BEGIN\n 0.00       - -0.000      1        -      -  warnings::unimport\n 0.00       - -0.000      1        -      -  DynaLoader::dl_find_symbol\n 0.00       - -0.000      1        -      -  DynaLoader::dl_install_xsub\n 0.00       - -0.000      1        -      -  UNIVERSAL::VERSION\n 0.00       - -0.000      1        -      -  Foo::new\n</pre>\n\n<p>The two most expensive calls are the Class::MethodMaker::Constants::BEGIN and Class::MethodMaker::Engine::BEGIN blocks, which are obviously called at compile time only, so they may slow the compilation of your script slightly, but subsequent object creation/accessor usage is not affected by it.</p>\n'}, {'answer_id': 63863, 'author': 'David Precious', 'author_id': 4040, 'author_profile': 'https://Stackoverflow.com/users/4040', 'pm_score': 0, 'selected': False, 'text': '<p>Further to my previous answer, if you want to see exactly what\'s going on under the hood in detail, run your script in the debugger with trace mode on (perl -d filename.pl, then say "t" to trace, then "r" to run the script; expect a lot of output though!).</p>\n'}, {'answer_id': 70574, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 3, 'selected': True, 'text': "<p>I don't have a simple answer for your question regarding Class::MethodMaker performance. As a previous answer mentioned, you can use the debugger to find out what's going on under the hood. However, I know that Class::MethodMaker generates <em>huge</em> amounts of code at install time. This would indicate three separate things to me:</p>\n\n<ol>\n<li>Regarding run-time, it's <em>probably</em> on the faster side of the whole slew of method generators. Why generate loads of code at install time otherwise?</li>\n<li>It installs O(Megabytes) of code on your disk!</li>\n<li>It may potentially be slow at compile time, depending on what parts of the generated code are loaded for simple use cases.</li>\n</ol>\n\n<p>You really need to spend a few minutes to think about what you really need. If you want simple accessor methods auto-generated but write anything more complicated by hand, maybe look at Class::Accessor::Fast. Or, if you want the fastest possible accessor-methods, investigate Class::XSAccessor, whose extra-simple methods run as C/XS code and are approximately twice as fast as the fastest Perl accessor. (Note: I wrote the latter module, so take this with a grain of salt.)</p>\n\n<p>One further comment: if you're ever going to use the PAR/PAR::Packer toolkit for packaging your application, note that the large amount of code of Class::MethodMaker results in a significantly larger executable and a slower initial start-up time. Additionally, there's a known incompatibility between C::MethodMaker and PAR. But that may be considered a PAR bug.</p>\n"}]
['https://Stackoverflow.com/questions/62102', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/4406/']