whitequark / ast

A library for working with Abstract Syntax Trees.
MIT License
195 stars 25 forks source link

Use `alias` for definition of `AST::Node#to_a` #17

Closed pocke closed 7 years ago

pocke commented 7 years ago

By this change, the method will be faster around 33%.

Benchmark

$ time ruby -rast -e 'node = AST::Node.new(:foo, [1,2,3,4,5]); 100000000.times{node.to_a}'

Result

before after
1st 4.47 2.89
2nd 4.10 3.03
3rd 4.56 2.75
4th 4.57 2.84
5th 4.15 3.13
avg 4.37 2.928

Note

The method is small, but it is called many times by applications(e.g. RuboCop). So, I think this change makes sense.

coveralls commented 7 years ago

Coverage Status

Coverage remained the same at 100.0% when pulling 6519599241cff7bc99cc0ccc5bac4a22a6bb9615 on pocke:alias into 93c43433ec4d4344485eb4ea6f8948925f092af1 on whitequark:master.

pocke commented 7 years ago

Fixed 170430195739

coveralls commented 7 years ago

Coverage Status

Coverage remained the same at 100.0% when pulling 04630729a1dd4daca83c9d31184de80b2aebf38d on pocke:alias into 93c43433ec4d4344485eb4ea6f8948925f092af1 on whitequark:master.

coveralls commented 7 years ago

Coverage Status

Coverage remained the same at 100.0% when pulling 04dc37f20eab145d9a8b6d1de7fe35950c1a06f8 on pocke:alias into 93c43433ec4d4344485eb4ea6f8948925f092af1 on whitequark:master.