Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Strftime to improve fixed timestamp performance #1796

Merged
merged 4 commits into from
Jan 11, 2018

Conversation

repeatedly
Copy link
Member

Use Strftime instead of Time#strftime improves the performance of time formatting.

@repeatedly repeatedly self-assigned this Dec 19, 2017
@repeatedly repeatedly added enhancement Feature request or improve operations v1 labels Dec 19, 2017
@repeatedly
Copy link
Member Author

@mururu Could you also check this?


config_param :output_type, :string, default: 'json'

def configure(conf)
super

@time_formatter = Strftime.new(TIME_FORMAT)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't we need rescue nil here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes because TIME_FORMAT is fixed.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see.

@formatter = Proc.new { |type, time, level, msg|
r = {
'time' => time.strftime(@time_format),
'time' => @time_formatter ? @time_formatter.exec(time) : time.strftime(@time_format),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about defining method for @time_formatter ? @time_formatter.exec(time) : time.strftime(@time_format)?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@mururu
Copy link
Member

mururu commented Jan 5, 2018

Looks good.

@repeatedly repeatedly merged commit 3b71fef into master Jan 11, 2018
@repeatedly repeatedly deleted the use-precompiled-strftime branch January 11, 2018 09:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Feature request or improve operations v1
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants