Grokking Advanced Go
0% completed
Writing Benchmarks
The benchmark below compiles, runs, and prints a believable number, and that number is wrong. It measures the total of an order with 100 items, and each item needs a multiplication and a tax calculation.
// file: order.go package order import ( "fmt" "strings" ) type Item struct { SKU string Quantity int Cents int64 // price of one unit, in cents } type Order struct { ID int64 Customer string Items []Item Paid bool } // LineCents returns one line's price plus 7.5 percent tax, rounded up. func (i Item) LineCents() int64 { line := int64(i.Quantity) * i
.....
.....
.....
Like the course? Get enrolled and start learning!
Reading Progress
0%