]>
Dogcows Code - chaz/p5-CGI-Ex/blob - samples/benchmark/bench_optree.pl
5 bench_optree.pl - Look at different ways of storing data that transform fast.
10 use Benchmark
qw(cmpthese timethese);
11 use CGI
::Ex
::Dump
qw(debug);
12 use constant skip_execute
=> 1;
14 #my $obj = bless [1, 2], __PACKAGE__;
15 #my $struct1 = \ [ '-', 1, 2 ];
16 #my $struct2 = ['-', 1, 2];
18 #sub call { $_[0]->[0] - $_[0]->[1] }
20 #sub obj_meth { $obj->call }
21 #sub ref_type { if (ref($struct1) eq 'REF') { if (${$struct1}->[0] eq '-') { ${$struct1}->[1] - ${$struct1}->[2] } } }
23 #print "(".obj_meth().")\n";
24 #print "(".ref_type().")\n";
25 #cmpthese timethese(-2, {
26 # obj_meth => \&obj_meth,
27 # ref_type => \&ref_type,
31 ###----------------------------------------------------------------###
32 ### setup a new way of storing and executing the variable tree
34 sub get_var2
{ ref($_[1]) ? $_[1]->call($_[0]) : $_[1] }
38 sub new
{ my $c = shift; bless \
@_, $c };
39 sub call
{ $_[0]->[0] }
41 sub new
{ my $c = shift; bless \
@_, $c }
42 # sub new { my $c = shift; bless [map{ref$_?$_:Num->new($_)} @_], $c }
45 sub call
{ $_[1]->get_var2($_[0]->[0]) - $_[1]->get_var2($_[0]->[1]) }
48 sub call
{ $_[1]->get_var2($_[0]->[0]) + $_[1]->get_var2($_[0]->[1]) }
51 sub call
{ $_[1]->get_var2($_[0]->[0]) * $_[1]->get_var2($_[0]->[1]) }
54 sub call
{ $_[1]->get_var2($_[0]->[0]) / $_[1]->get_var2($_[0]->[1]) }
57 use vars
qw($HASH_OPS $LIST_OPS $SCALAR_OPS $FILTER_OPS $OP_FUNC);
59 $HASH_OPS = $CGI::Ex
::Template
::HASH_OPS
;
60 $LIST_OPS = $CGI::Ex
::Template
::LIST_OPS
;
61 $SCALAR_OPS = $CGI::Ex
::Template
::SCALAR_OPS
;
62 $FILTER_OPS = $CGI::Ex
::Template
::FILTER_OPS
;
63 $OP_FUNC = $CGI::Ex
::Template
::OP_FUNC
;
65 use constant trace
=> 0;
69 my $ARGS = shift || {};
73 ### determine the top level of this particular variable access
74 my $ref = $var->[$i++];
75 my $args = $var->[$i++];
76 warn "get_variable: begin \"$ref\"\n" if trace
;
79 if ($ARGS->{'is_namespace_during_compile'}) {
80 $ref = $self->{'NAMESPACE'}->{$ref};
82 return if $ref =~ /^[_.]/; # don't allow vars that begin with _
83 $ref = $self->{'_vars'}->{$ref};
88 while (defined $ref) {
90 ### check at each point if the returned thing was a code
91 if (UNIVERSAL
::isa
($ref, 'CODE')) {
92 my @results = $ref->($args ? @{ $self->vivify_args($args) } : ());
93 if (defined $results[0]) {
94 $ref = ($#results > 0) ? \
@results : $results[0];
95 } elsif (defined $results[1]) {
96 die $results[1]; # TT behavior - why not just throw ?
103 ### descend one chained level
104 last if $i >= $#$var;
105 my $was_dot_call = $ARGS->{'no_dots'} ? 1 : $var->[$i++] eq '.';
106 my $name = $var->[$i++];
107 my $args = $var->[$i++];
108 warn "get_variable: nested \"$name\"\n" if trace
;
110 ### allow for named portions of a variable name (foo.$name.bar)
112 $name = $name->call($self);
113 if (! defined($name) || $name =~ /^[_.]/) {
119 if ($name =~ /^_/) { # don't allow vars that begin with _
124 ### allow for scalar and filter access (this happens for every non virtual method call)
126 if ($SCALAR_OPS->{$name}) { # normal scalar op
127 $ref = $SCALAR_OPS->{$name}->($ref, $args ? @{ $self->vivify_args($args) } : ());
129 } elsif ($LIST_OPS->{$name}) { # auto-promote to list and use list op
130 $ref = $LIST_OPS->{$name}->([$ref], $args ? @{ $self->vivify_args($args) } : ());
132 } elsif (my $filter = $self->{'FILTERS'}->{$name} # filter configured in Template args
133 || $FILTER_OPS->{$name} # predefined filters in CET
134 || (UNIVERSAL
::isa
($name, 'CODE') && $name) # looks like a filter sub passed in the stash
135 || $self->list_filters->{$name}) { # filter defined in Template::Filters
137 if (UNIVERSAL
::isa
($filter, 'CODE')) {
138 $ref = eval { $filter->($ref) }; # non-dynamic filter - no args
140 $self->throw('filter', $err) if ref($err) !~ /Template::Exception$/;
143 } elsif (! UNIVERSAL
::isa
($filter, 'ARRAY')) {
144 $self->throw('filter', "invalid FILTER entry for '$name' (not a CODE ref)");
146 } elsif (@$filter == 2 && UNIVERSAL
::isa
($filter->[0], 'CODE')) { # these are the TT style filters
148 my $sub = $filter->[0];
149 if ($filter->[1]) { # it is a "dynamic filter" that will return a sub
150 ($sub, my $err) = $sub->($self->context, $args ? @{ $self->vivify_args($args) } : ());
151 if (! $sub && $err) {
152 $self->throw('filter', $err) if ref($err) !~ /Template::Exception$/;
154 } elsif (! UNIVERSAL
::isa
($sub, 'CODE')) {
155 $self->throw('filter', "invalid FILTER for '$name' (not a CODE ref)")
156 if ref($sub) !~ /Template::Exception$/;
163 $self->throw('filter', $err) if ref($err) !~ /Template::Exception$/;
166 } else { # this looks like our vmethods turned into "filters" (a filter stored under a name)
167 $self->throw('filter', 'Recursive filter alias \"$name\"') if $seen_filters{$name} ++;
168 $var = [$name, 0, '|', @$filter, @{$var}[$i..$#$var]]; # splice the filter into our current tree
171 if (scalar keys %seen_filters
172 && $seen_filters{$var->[$i - 5] || ''}) {
173 $self->throw('filter', "invalid FILTER entry for '".$var->[$i - 5]."' (not a CODE ref)");
181 ### method calls on objects
182 if (UNIVERSAL
::can
($ref, 'can')) {
183 my @args = $args ? @{ $self->vivify_args($args) } : ();
184 my @results = eval { $ref->$name(@args) };
186 die $@ if ref $@ || $@ !~ /Can\'t locate object method/;
187 } elsif (defined $results[0]) {
188 $ref = ($#results > 0) ? \
@results : $results[0];
190 } elsif (defined $results[1]) {
191 die $results[1]; # TT behavior - why not just throw ?
196 # didn't find a method by that name - so fail down to hash and array access
199 ### hash member access
200 if (UNIVERSAL
::isa
($ref, 'HASH')) {
201 if ($was_dot_call && exists($ref->{$name}) ) {
202 $ref = $ref->{$name};
203 } elsif ($HASH_OPS->{$name}) {
204 $ref = $HASH_OPS->{$name}->($ref, $args ? @{ $self->vivify_args($args) } : ());
205 } elsif ($ARGS->{'is_namespace_during_compile'}) {
206 return $var; # abort - can't fold namespace variable
212 } elsif (UNIVERSAL
::isa
($ref, 'ARRAY')) {
213 if ($name =~ /^\d+$/) {
214 $ref = ($name > $#$ref) ? undef : $ref->[$name];
216 $ref = (! $LIST_OPS->{$name}) ? undef : $LIST_OPS->{$name}->($ref, $args ? @{ $self->vivify_args($args) } : ());
223 ### allow for undefinedness
224 if (! defined $ref) {
225 if ($self->{'_debug_undef'}) {
226 my $chunk = $var->[$i - 2];
227 $chunk = $chunk->call($self) if ref $chunk;
228 die "$chunk is undefined\n";
230 $ref = $self->undefined_any($var);
234 ### allow for special behavior for the '..' operator
235 if ($generated_list && $ARGS->{'list_context'} && ref($ref) eq 'ARRAY') {
242 sub plus
($$) { A
::B
::Plus-
>new( @_) }
243 sub minus
($$) { A
::B
::Minus-
>new(@_) }
244 sub mult
($$) { A
::B
::Mult-
>new( @_) }
245 sub div
($$) { A
::B
::Div-
>new( @_) }
246 sub var
{ A
::B
::Var-
>new( @_) };
248 $INC{'A/B/Plus.pm'} = 1;
249 $INC{'A/B/Minus.pm'} = 1;
250 $INC{'A/B/Mult.pm'} = 1;
251 $INC{'A/B/Div.pm'} = 1;
252 $INC{'A/B/Var.pm'} = 1;
254 ###----------------------------------------------------------------###
255 ### now benchmark the different variable storage methods
258 foo
=> {bar
=> {baz
=> [qw(a b c)]}},
261 my $self = bless {'_vars' => $vars}, __PACKAGE__
;
263 #pauls@pslaptop:~/perl/CGI-Ex/lib$ perl -e 'my $a = "1 + 2 * (3 + (4 / 5) * 9) - 20";
264 # use CGI::Ex::Template;
266 # print Dumper(CGI::Ex::Template->new->parse_variable(\$a));'
268 ###----------------------------------------------------------------###
270 my $Y0 = '$self->{_vars}->{bing}';
271 my $Y1 = [ 'bing', 0 ];
272 my $Y2 = var
('bing', 0);
275 ### are they all the same
276 print eval($Y0)."\n";
277 print $self->get_variable($Y1)."\n";
278 print $self->get_var2($Y2)."\n";
280 if (! skip_execute
) {
281 cmpthese timethese
(-2, {
282 perl
=> sub { eval $Y0 },
283 bare_data
=> sub { $self->get_variable($Y1) },
284 method_call
=> sub { $self->get_var2($Y2) },
288 ###----------------------------------------------------------------###
290 my $Z0 = '$self->{_vars}->{foo}->{bar}->{baz}->[1]';
291 my $Z1 = [ 'foo', 0, '.', 'bar', 0, '.', 'baz', 0, '.', 1, 0];
292 my $Z2 = var
('foo', 0, '.', 'bar', 0, '.', 'baz', 0, '.', 1, 0);
295 ### are they all the same
296 print eval($Z0)."\n";
297 print $self->get_variable($Z1)."\n";
298 print $self->get_var2($Z2)."\n";
300 if (! skip_execute
) {
301 cmpthese timethese
(-2, {
302 perl
=> sub { eval $Z0 },
303 bare_data
=> sub { $self->get_variable($Z1) },
304 method_call
=> sub { $self->get_var2($Z2) },
308 ###----------------------------------------------------------------###
310 ### $A0 = perl, $A1 = old optree, $A2 = new optree
311 my $A0 = "1 + 2 * (3 + (4 / 5) * 9) - 20";
312 my $A1 = [ \
[ '-', [ \
[ '+', '1', [ \
[ '*', '2', [ \
[ '+', '3', [ \
[ '*', [ \
[ '/', '4', '5' ], 0 ], '9' ], 0 ] ], 0 ] ], 0 ] ], 0 ], '20' ], 0 ];
313 my $A2 = minus
(plus
(1, mult
(2, plus
(3, mult
(div
(4,5), 9)))), 20);
316 ### are they all the same
317 print eval($A0)."\n";
318 print $self->get_variable($A1)."\n";
319 print $self->get_var2($A2)."\n";
321 if (! skip_execute
) {
322 cmpthese timethese
(-2, {
323 perl
=> sub { eval $A0 },
324 bare_data
=> sub { $self->get_variable($A1) },
325 method_call
=> sub { $self->get_var2($A2) },
329 ###----------------------------------------------------------------###
332 my $B1 = [ \
[ '+', 1, 2] ];
336 ### are they all the same
337 print eval($B0)."\n";
338 print $self->get_variable($B1)."\n";
339 print $self->get_var2($B2)."\n";
341 if (! skip_execute
) {
342 cmpthese timethese
(-2, {
343 perl
=> sub { eval $B0 },
344 bare_data
=> sub { $self->get_variable($B1) },
345 method_call
=> sub { $self->get_var2($B2) },
349 ###----------------------------------------------------------------###
350 ### Test (de)serialization speed
353 my $d1 = Storable
::freeze
($A1);
354 my $d2 = Storable
::freeze
($A2);
355 Storable
::thaw
($d1); # load lib
356 print length($d1)."\n";
357 print length($d2)."\n";
359 cmpthese timethese
(-2, {
360 freeze_bare
=> sub { Storable
::freeze
($A1) },
361 freeze_meth
=> sub { Storable
::freeze
($A2) },
364 cmpthese timethese
(-2, {
365 thaw_bare
=> sub { Storable
::thaw
($d1) },
366 thaw_meth
=> sub { Storable
::thaw
($d2) },
369 ###----------------------------------------------------------------###
370 ### create libraries similar to those from CGI::Ex::Template 1.201
372 use CGI
::Ex
::Template
;
373 use vars
qw($HASH_OPS $LIST_OPS $SCALAR_OPS $FILTER_OPS $OP_FUNC);
375 $HASH_OPS = $CGI::Ex
::Template
::HASH_OPS
;
376 $LIST_OPS = $CGI::Ex
::Template
::LIST_OPS
;
377 $SCALAR_OPS = $CGI::Ex
::Template
::SCALAR_OPS
;
378 $FILTER_OPS = $CGI::Ex
::Template
::FILTER_OPS
;
379 $OP_FUNC = $CGI::Ex
::Template
::OP_FUNC
;
381 use constant trace
=> 0;
384 ### allow for the parse tree to store literals
385 return $_[1] if ! ref $_[1];
389 my $ARGS = shift || {};
393 ### determine the top level of this particular variable access
394 my $ref = $var->[$i++];
395 my $args = $var->[$i++];
396 warn "get_variable: begin \"$ref\"\n" if trace
;
398 if (ref($ref) eq 'SCALAR') { # a scalar literal
400 } elsif (ref($ref) eq 'REF') { # operator
401 return $self->play_operator($$ref) if ${ $ref }->[0] eq '\\'; # return the closure
402 $generated_list = 1 if ${ $ref }->[0] eq '..';
403 $ref = $self->play_operator($$ref);
404 } else { # a named variable access (ie via $name.foo)
405 $ref = $self->get_variable($ref);
407 return if $ref =~ /^[_.]/; # don't allow vars that begin with _
408 $ref = $self->{'_vars'}->{$ref};
411 } elsif (defined $ref) {
412 if ($ARGS->{'is_namespace_during_compile'}) {
413 $ref = $self->{'NAMESPACE'}->{$ref};
415 return if $ref =~ /^[_.]/; # don't allow vars that begin with _
416 $ref = $self->{'_vars'}->{$ref};
422 while (defined $ref) {
424 ### check at each point if the returned thing was a code
425 if (UNIVERSAL
::isa
($ref, 'CODE')) {
426 my @results = $ref->($args ? @{ $self->vivify_args($args) } : ());
427 if (defined $results[0]) {
428 $ref = ($#results > 0) ? \
@results : $results[0];
429 } elsif (defined $results[1]) {
430 die $results[1]; # TT behavior - why not just throw ?
437 ### descend one chained level
438 last if $i >= $#$var;
439 my $was_dot_call = $ARGS->{'no_dots'} ? 1 : $var->[$i++] eq '.';
440 my $name = $var->[$i++];
441 my $args = $var->[$i++];
442 warn "get_variable: nested \"$name\"\n" if trace
;
444 ### allow for named portions of a variable name (foo.$name.bar)
446 if (ref($name) eq 'ARRAY') {
447 $name = $self->get_variable($name);
448 if (! defined($name) || $name =~ /^[_.]/) {
453 die "Shouldn't get a ". ref($name) ." during a vivify on chain";
456 if ($name =~ /^_/) { # don't allow vars that begin with _
461 ### allow for scalar and filter access (this happens for every non virtual method call)
463 if ($SCALAR_OPS->{$name}) { # normal scalar op
464 $ref = $SCALAR_OPS->{$name}->($ref, $args ? @{ $self->vivify_args($args) } : ());
466 } elsif ($LIST_OPS->{$name}) { # auto-promote to list and use list op
467 $ref = $LIST_OPS->{$name}->([$ref], $args ? @{ $self->vivify_args($args) } : ());
469 } elsif (my $filter = $self->{'FILTERS'}->{$name} # filter configured in Template args
470 || $FILTER_OPS->{$name} # predefined filters in CET
471 || (UNIVERSAL
::isa
($name, 'CODE') && $name) # looks like a filter sub passed in the stash
472 || $self->list_filters->{$name}) { # filter defined in Template::Filters
474 if (UNIVERSAL
::isa
($filter, 'CODE')) {
475 $ref = eval { $filter->($ref) }; # non-dynamic filter - no args
477 $self->throw('filter', $err) if ref($err) !~ /Template::Exception$/;
480 } elsif (! UNIVERSAL
::isa
($filter, 'ARRAY')) {
481 $self->throw('filter', "invalid FILTER entry for '$name' (not a CODE ref)");
483 } elsif (@$filter == 2 && UNIVERSAL
::isa
($filter->[0], 'CODE')) { # these are the TT style filters
485 my $sub = $filter->[0];
486 if ($filter->[1]) { # it is a "dynamic filter" that will return a sub
487 ($sub, my $err) = $sub->($self->context, $args ? @{ $self->vivify_args($args) } : ());
488 if (! $sub && $err) {
489 $self->throw('filter', $err) if ref($err) !~ /Template::Exception$/;
491 } elsif (! UNIVERSAL
::isa
($sub, 'CODE')) {
492 $self->throw('filter', "invalid FILTER for '$name' (not a CODE ref)")
493 if ref($sub) !~ /Template::Exception$/;
500 $self->throw('filter', $err) if ref($err) !~ /Template::Exception$/;
503 } else { # this looks like our vmethods turned into "filters" (a filter stored under a name)
504 $self->throw('filter', 'Recursive filter alias \"$name\"') if $seen_filters{$name} ++;
505 $var = [$name, 0, '|', @$filter, @{$var}[$i..$#$var]]; # splice the filter into our current tree
508 if (scalar keys %seen_filters
509 && $seen_filters{$var->[$i - 5] || ''}) {
510 $self->throw('filter', "invalid FILTER entry for '".$var->[$i - 5]."' (not a CODE ref)");
518 ### method calls on objects
519 if (UNIVERSAL
::can
($ref, 'can')) {
520 my @args = $args ? @{ $self->vivify_args($args) } : ();
521 my @results = eval { $ref->$name(@args) };
523 die $@ if ref $@ || $@ !~ /Can\'t locate object method/;
524 } elsif (defined $results[0]) {
525 $ref = ($#results > 0) ? \
@results : $results[0];
527 } elsif (defined $results[1]) {
528 die $results[1]; # TT behavior - why not just throw ?
533 # didn't find a method by that name - so fail down to hash and array access
536 ### hash member access
537 if (UNIVERSAL
::isa
($ref, 'HASH')) {
538 if ($was_dot_call && exists($ref->{$name}) ) {
539 $ref = $ref->{$name};
540 } elsif ($HASH_OPS->{$name}) {
541 $ref = $HASH_OPS->{$name}->($ref, $args ? @{ $self->vivify_args($args) } : ());
542 } elsif ($ARGS->{'is_namespace_during_compile'}) {
543 return $var; # abort - can't fold namespace variable
549 } elsif (UNIVERSAL
::isa
($ref, 'ARRAY')) {
550 if ($name =~ /^\d+$/) {
551 $ref = ($name > $#$ref) ? undef : $ref->[$name];
553 $ref = (! $LIST_OPS->{$name}) ? undef : $LIST_OPS->{$name}->($ref, $args ? @{ $self->vivify_args($args) } : ());
560 ### allow for undefinedness
561 if (! defined $ref) {
562 if ($self->{'_debug_undef'}) {
563 my $chunk = $var->[$i - 2];
564 $chunk = $self->get_variable($chunk) if ref($chunk) eq 'ARRAY';
565 die "$chunk is undefined\n";
567 $ref = $self->undefined_any($var);
571 ### allow for special behavior for the '..' operator
572 if ($generated_list && $ARGS->{'list_context'} && ref($ref) eq 'ARRAY') {
582 my $args = shift || {};
583 return [map {$self->get_variable($_, $args)} @$vars];
589 my $ARGS = shift || {};
591 $tree = [@$tree[1..$#$tree]];
593 ### allow for operator function override
594 if (exists $OP_FUNC->{$op}) {
595 return $OP_FUNC->{$op}->($self, $op, $tree, $ARGS);
598 ### do constructors and short-circuitable operators
599 if ($op eq '~' || $op eq '_') {
600 return join "", grep {defined} @{ $self->vivify_args($tree) };
601 } elsif ($op eq 'arrayref') {
602 return $self->vivify_args($tree, {list_context
=> 1});
603 } elsif ($op eq 'hashref') {
604 my $args = $self->vivify_args($tree);
605 push @$args, undef if ! ($#$args % 2);
607 } elsif ($op eq '?') {
608 if ($self->get_variable($tree->[0])) {
609 return defined($tree->[1]) ? $self->get_variable($tree->[1]) : undef;
611 return defined($tree->[2]) ? $self->get_variable($tree->[2]) : undef;
613 } elsif ($op eq '||' || $op eq 'or' || $op eq 'OR') {
614 for my $node (@$tree) {
615 my $var = $self->get_variable($node);
619 } elsif ($op eq '&&' || $op eq 'and' || $op eq 'AND') {
621 for my $node (@$tree) {
622 $var = $self->get_variable($node);
627 } elsif ($op eq '!') {
628 my $var = ! $self->get_variable($tree->[0]);
629 return defined($var) ? $var : '';
633 ### equality operators
635 my $n = $self->get_variable($tree->[0]);
636 $tree = [@$tree[1..$#$tree]];
637 if ($op eq '==') { for (@$tree) { $_ = $self->get_variable($_); return '' if ! ($n eq $_) }; return 1 }
638 elsif ($op eq '!=') { for (@$tree) { $_ = $self->get_variable($_); return '' if ! ($n ne $_) }; return 1 }
639 elsif ($op eq 'eq') { for (@$tree) { $_ = $self->get_variable($_); return '' if ! ($n eq $_) }; return 1 }
640 elsif ($op eq 'ne') { for (@$tree) { $_ = $self->get_variable($_); return '' if ! ($n ne $_) }; return 1 }
641 elsif ($op eq '<') { for (@$tree) { $_ = $self->get_variable($_); return '' if ! ($n < $_); $n = $_ }; return 1 }
642 elsif ($op eq '>') { for (@$tree) { $_ = $self->get_variable($_); return '' if ! ($n > $_); $n = $_ }; return 1 }
643 elsif ($op eq '<=') { for (@$tree) { $_ = $self->get_variable($_); return '' if ! ($n <= $_); $n = $_ }; return 1 }
644 elsif ($op eq '>=') { for (@$tree) { $_ = $self->get_variable($_); return '' if ! ($n >= $_); $n = $_ }; return 1 }
645 elsif ($op eq 'lt') { for (@$tree) { $_ = $self->get_variable($_); return '' if ! ($n lt $_); $n = $_ }; return 1 }
646 elsif ($op eq 'gt') { for (@$tree) { $_ = $self->get_variable($_); return '' if ! ($n gt $_); $n = $_ }; return 1 }
647 elsif ($op eq 'le') { for (@$tree) { $_ = $self->get_variable($_); return '' if ! ($n le $_); $n = $_ }; return 1 }
648 elsif ($op eq 'ge') { for (@$tree) { $_ = $self->get_variable($_); return '' if ! ($n ge $_); $n = $_ }; return 1 }
650 ### numeric operators
651 my $args = $self->vivify_args($tree);
653 if ($op eq '-') { return - $n }
654 $self->throw('operator', "Not enough args for operator \"$op\"");
656 if ($op eq '..') { return [($n || 0) .. ($args->[-1] || 0)] }
657 elsif ($op eq '+') { $n += $_ for @$args; return $n }
658 elsif ($op eq '-') { $n -= $_ for @$args; return $n }
659 elsif ($op eq '*') { $n *= $_ for @$args; return $n }
660 elsif ($op eq '/') { $n /= $_ for @$args; return $n }
662 || $op eq 'DIV') { $n = int($n / $_) for @$args; return $n }
665 || $op eq 'MOD') { $n %= $_ for @$args; return $n }
667 || $op eq 'pow') { $n **= $_ for @$args; return $n }
669 $self->throw('operator', "Un-implemented operation $op");
This page took 0.09746 seconds and 4 git commands to generate.