Skip to content

Commit

Permalink
Update readme.markdown
Browse files Browse the repository at this point in the history
  • Loading branch information
yourheropaul committed Aug 26, 2015
1 parent fc1d31f commit e1f0d57
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions readme.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ I appreciate your skepticism, so let's gather some data. There are two things yo

The first is that the application graph is one dimensional and indexed by type. That means you can't call `inj.Provide(someIntValue,someOtherIntValue)` and expect both integers to be in the graph – the second will override the first. Other depdendency injection approaches allow for named and private depdendencies, but that has been sacrified here so that `inj.Inject()` could exist in a consistent way. When there's a choice, `inj` errs on the side of simplicity, consistency and idiomatic implementation over complexity and magic.

The second consideration is execution speed. Obviously, calling `inj.Inject(fn)` is slower than calling `fn()` directly. In Go 1.4, with a medium-sized graph, it takes about 350 times longer to execute the call; in Go 1.5 rc1, it's about 250 times. If those numbers seem high, it's because they are. The impact on an application is measurable, but for most purposes negligible.
The second consideration is execution speed. Obviously, calling `inj.Inject(fn)` is slower than calling `fn()` directly. In Go 1.4, with a medium-sized graph, it takes about 350 times longer to execute the call; in Go 1.5 rc1, it's about 240 times. If those numbers seem high, it's because they are. The impact on an application is measurable, but for most purposes negligible.

If the average execution time of a pure Go function is around 4 nanoseconds (as it is in my tests) then the execution time of `inj.Inject()` will be somewhere between 1,000 and 1,400 nanoseconds. Or in more useful terms, 0.0014 milliseconds (which is 1.4e-6 seconds). If your application is built for speed, then you will need to be judicious in your use of `inj.Inect()`. Even if speed isn't a concern, it's generally not a good idea to nest injection calls, or put them in loops.
If the average execution time of a pure Go function is around 4 nanoseconds (as it is in my tests) then the execution time of `inj.Inject()` will be somewhere between 900 and 1,400 nanoseconds. Or in more useful terms, 0.0014 milliseconds (which is 1.4e-6 seconds). If your application is built for speed, then you will need to be judicious in your use of `inj.Inect()`. Even if speed isn't a concern, it's generally not a good idea to nest injection calls, or put them in loops.

Finally, `inj.Provide()` is fairly slow, but it's designed to executed at runtime only. There are benchmark tests in the package if you want to see how it performs on your system.

Expand Down

0 comments on commit e1f0d57

Please sign in to comment.