Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 4th, 2012  |  syntax: None  |  size: 0.41 KB  |  hits: 15  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. // go code
  2. package main
  3.  
  4. const LEN = 100000
  5.  
  6. type bench interface {
  7.         get() int
  8. }
  9.  
  10. type B struct {
  11.         bench
  12. }
  13.  
  14. func (b *B) get() int {
  15.         return 1
  16. }
  17.  
  18. type C struct {
  19.         bench
  20. }
  21.  
  22. func (c *C) get() int {
  23.         return 2
  24. }
  25.  
  26. func main() {
  27.         //a := new(B)
  28.         // meaning get() of B
  29.         f := func() int {
  30.                 return 1
  31.         }
  32.         sum := 0
  33.         for i := 0; i < LEN; i++ {
  34.                 sum2 := 0
  35.                 for j := 0; j < LEN; j++ {
  36.                         sum2 += f()
  37.                 }
  38.                 sum += sum2
  39.         }
  40.         println(sum)
  41. }