optparse

C

Charles Mills

We recently switched to using optparse from getoptlong in the DBC for C
project, because optparse is much more flexible and generally just
better.

Is there any way to parse options of the form '-word arg' like
'-include "config.h"'?

Also noticed their is a preformance price for using optparse.
Switching to optparse from getoptlong slowed down the main benchmark we
run from ~3.5sec to about ~4.5sec. Isn't that big of a deal I guess,
but food for thought.

-Charlie
 
E

Eric Hodel

--Apple-Mail-6-546765557
Content-Transfer-Encoding: 7bit
Content-Type: text/plain; charset=US-ASCII; format=flowed

Also noticed their is a preformance price for using optparse.
Switching to optparse from getoptlong slowed down the main benchmark we
run from ~3.5sec to about ~4.5sec. Isn't that big of a deal I guess,
but food for thought.

What kind of hardware are you running, and how many options do you
have? I can't imagine how many options you have that adds an extra
second to runtime.

--
Eric Hodel - (e-mail address removed) - http://segment7.net
FEC2 57F1 D465 EB15 5D6E 7C11 332A 551C 796C 9F04

--Apple-Mail-6-546765557
content-type: application/pgp-signature; x-mac-type=70674453;
name=PGP.sig
content-description: This is a digitally signed message part
content-disposition: inline; filename=PGP.sig
content-transfer-encoding: 7bit

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (Darwin)

iD8DBQFB5XAtMypVHHlsnwQRAiHKAJ0cHlIM2M05PjrdfbYLHKToERW48ACgtqaQ
c/5fae2CBbN/hE7TxxHXdVs=
=IolZ
-----END PGP SIGNATURE-----

--Apple-Mail-6-546765557--
 
C

Charles Mills

Eric said:
What kind of hardware are you running, and how many options do you
have? I can't imagine how many options you have that adds an extra
second to runtime.

12 options. Running a 1ghz powerbook.

Any idea about the first question? Seems like you can only do "--word
arg" or "-c arg", not "-word arg".

-Charlie
 
D

Daniel Berger

Does running it through the profiler provide any insight?
As to your other question, I'm afraid I just don't know.

Dan
 
G

Glenn Parker

Charles said:
Any idea about the first question? Seems like you can only do "--word
arg" or "-c arg", not "-word arg".

I think that's the style you get. A double hypen is always followed by
a long option name. A single hyphen is always followed by a one-letter
option flag.
 
R

Robert Klemme

Glenn Parker said:
I think that's the style you get. A double hypen is always followed by a
long option name. A single hyphen is always followed by a one-letter
option flag.

I'm not 100% sure but that might even be POSIX standard. Anyway, IMHO it's
a good convention to follow.

robert
 
C

Charles Mills

Daniel said:
Does running it through the profiler provide any insight?
As to your other question, I'm afraid I just don't know.

So I ran it through the profiler and the last line below jumped out at
me.

% cumulative self self total
time seconds seconds calls ms/call ms/call name
12.22 5.00 5.00 3759 1.33 3.38
Preprocessor::Tokens#shift
11.78 9.82 4.82 4055 1.19 1.58
CTokenizer::Lexer#shift
6.38 12.43 2.61 667 3.91 10.69 Array#each
4.25 14.17 1.74 21566 0.08 0.08 Array#at
4.23 15.90 1.73 1553 1.11 1.62
CTokenizer::Scoped.process_scope
4.06 17.56 1.66 1550 1.07 14.74 Kernel.loop
3.72 19.08 1.52 20222 0.08 0.08 Kernel.==
3.08 20.34 1.26 1483 0.85 19.82 DBC::parser#shift
2.86 21.51 1.17 1553 0.75 16.37
Preprocessor::parser#shift
2.76 22.64 1.13 383 2.95 127.36
Racc::parser#_racc_do_parse_c
(...)
0.15 38.69 0.06 13 4.62 43.08
OptionParser#make_switch
0.15 38.75 0.06 50 1.20 1.80
CType::parser#_reduce_113
0.12 38.80 0.05 81 0.62 0.62
CTokenizer::Splitter#reset
0.12 38.85 0.05 302 0.17 0.33
Preprocessor::parser#_reduce_1
0.12 38.90 0.05 122 0.41 0.41 Hash#include?
0.12 38.95 0.05 366 0.14 0.14 Hash#[]=
0.12 39.00 0.05 105 0.48 1.62
CTokenizer::Splitter#shift
0.12 39.05 0.05 38 1.32 1.32 Hash#invert
0.12 39.10 0.05 54 0.93 4.81
Array#reverse_each
0.12 39.15 0.05 135 0.37 0.37
CType::parser#_reduce_114
0.12 39.20 0.05 135 0.37 1.48
CType::parser#_reduce_116
0.12 39.25 0.05 556 0.09 0.09 Array#<<
0.10 39.29 0.04 76 0.53 34.74
Preprocessor::parser#_reduce_9
0.10 39.33 0.04 58 0.69 0.69
CType::parser#_reduce_165
0.10 39.37 0.04 19 2.11 11.58
OptionParser::List#update
0.10 39.41 0.04 1 40.00 820.00
OptionParser#initialize
(...)

It may just be optparse creates more objects causing the GC to run more
often.

-Charlie
 
C

Charles Mills

Robert said:
I'm not 100% sure but that might even be POSIX standard. Anyway, IMHO it's
a good convention to follow.
Agreed. I am trying to mimic a few of gcc's command line options and
'-include file' is one of them. Looking at gcc's man page, they
certainly don't follow the double hyphen convention :(

-Charlie
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,164
Messages
2,570,898
Members
47,439
Latest member
shasuze

Latest Threads

Top