Skip to content

Optimize format time#10

Merged
ryanuber merged 4 commits intoryanuber:masterfrom
dadgar:master
Jun 28, 2016
Merged

Optimize format time#10
ryanuber merged 4 commits intoryanuber:masterfrom
dadgar:master

Conversation

@dadgar
Copy link
Contributor

@dadgar dadgar commented Jun 28, 2016

This PR reduces the time and number of allocations:

Old:
BenchmarkColumnWidthCalculator-4 5000 17636705 ns/op

New:
BenchmarkColumnWidthCalculator-4 30000 3215149 ns/op

columnize.go Outdated
Copy link
Owner

Choose a reason for hiding this comment

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

This should never really be this large because it is just the formatting of a single line, sans data. I would guess the size would end up being closer to (6 + len(c.Glue)) * columns (%-NNNs<glue> per-column). I'm fine with it though if there is some subtle reason the math is faster this way.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah good catch, the extra 8 is wrong. But I think len(width) ~= columns, but it is one less len() call so I will make the change.

@ryanuber
Copy link
Owner

@dadgar nice! This is looking really good. Left a few thoughts/comments.

@dadgar
Copy link
Contributor Author

dadgar commented Jun 28, 2016

Done!

@ryanuber
Copy link
Owner

🚢

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

Comments