Advertisement
Guest User

Untitled

a guest
Feb 12th, 2016
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.93 KB | None | 0 0
  1. package test
  2.  
  3. import (
  4. "math"
  5. "testing"
  6. )
  7.  
  8. //go:noinline
  9. func test64And(x uint64) uint64 {
  10. return (x &^ (1 << 63)) & 0x0F
  11. }
  12.  
  13. func Benchmark64Bit(b *testing.B) {
  14. for i := 0; i < b.N; i++ {
  15. _ = test64And(uint64(i))
  16. }
  17. }
  18.  
  19. //go:noinline
  20. func test32And(x uint32) uint32 {
  21. return (x &^ (1 << 31)) & 0x0F
  22. }
  23. func Benchmark32Bit(b *testing.B) {
  24. for i := 0; i < b.N; i++ {
  25. _ = test32And(uint32(i))
  26. }
  27. }
  28.  
  29. //go:noinline
  30. func test16And(x uint16) uint16 {
  31. return (x &^ (1 << 15)) & 0x0F
  32. }
  33. func Benchmark16Bit(b *testing.B) {
  34. for i := 0; i < b.N; i++ {
  35. _ = test16And(uint16(i))
  36. }
  37. }
  38.  
  39. //go:noinline
  40. func test8And(x uint8) uint8 {
  41. return ((x &^ (1 << 7)) & 0x0F)
  42. }
  43. func Benchmark8Bit(b *testing.B) {
  44. for i := 0; i < b.N; i++ {
  45. _ = test8And(uint8(i))
  46. }
  47. }
  48.  
  49. //go:noinline
  50. func Abs_ssa(x float64) float64 {
  51. return math.Float64frombits(math.Float64bits(x) &^ (1 << 63))
  52. }
  53. func BenchmarkAbs(b *testing.B) {
  54. for i := 0; i < b.N; i++ {
  55. _ = Abs_ssa(-1)
  56. }
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement