title: SNMP reading from an OID with three libraries gives different execution times
body: <p>I already used <code>easysnmp</code> to read SNMP OIDs, but I chose <code>pysnmp</code> library now because <code>easysnmp</code> did not support <code>asyncio</code> archtecture in <em>Python3</em>.</p>
  
  <p>The considered issue is that,<code>pysnmp</code> is too slower than other libraries:</p>
  
  <h1>pysnmp:</h1>
  
  <pre><code>from pysnmp.hlapi import *
  import time
  
  t = time.time()
  iterator = getCmd(SnmpEngine(),
                    CommunityData('public'),
                    UdpTransportTarget(('192.168.1.120', 161)),
                    ContextData(),
                    ObjectType(ObjectIdentity("1.3.6.1.2.1.33.1.2.7.0")))
  
  errorIndication, errorStatus, errorIndex, varBinds = next(iterator)
  
  if errorIndication:  # SNMP engine errors
      print(errorIndication)
  else:
      if errorStatus:  # SNMP agent errors
          print('%s at %s' % (
              errorStatus.prettyPrint(),
              varBinds[int(errorIndex)-1] if errorIndex else '?'))
      else:
          for varBind in varBinds:  # SNMP response contents
              print(' = '.join([x.prettyPrint() for x in varBind]))
  
  
  print(time.time() - t, 's') 
  </code></pre>
  
  <p>Out:</p>
  
  <pre><code>SNMPv2-SMI::mib-2.33.1.2.7.0 = 21
  0.15317177772521973 s
  </code></pre>
  
  <hr>
  
  <h1>easysnmp</h1>
  
  <pre><code>from easysnmp import snmp_get
  import time
  
  if __name__ == '__main__':
      t = time.time()
      response = snmp_get(
          '1.3.6.1.2.1.33.1.2.7.0', hostname='192.168.1.120',
          community='public', version=1
      )
      print(response.value)
      print(time.time() - t, 's')
  </code></pre>
  
  <p>Out:</p>
  
  <pre><code>21
  0.0063724517822265625 s
  </code></pre>
  
  <hr>
  
  <h1>gosnmp</h1>
  
  <pre><code>func elapsed(what string) func() {
      start := time.Now()
      fmt.Println("start")
      return func() {
          fmt.Printf("%s took %v\n", what, time.Since(start))
      }
  }
  
  func snmpRead() {
      g.Default.Target = "192.168.1.120"
      err := g.Default.Connect()
      if err != nil {
          log.Fatalf("Connect() err: %v", err)
      }
      defer g.Default.Conn.Close()
  
      oids := []string{"1.3.6.1.2.1.33.1.2.7.0"}
      result, err2 := g.Default.Get(oids) // Get() accepts up to g.MAX_OIDS
      if err2 != nil {
          log.Fatalf("Get() err: %v", err2)
      }
  
      for i, variable := range result.Variables {
          fmt.Printf("%d: oid: %s ", i, variable.Name)
  
          switch variable.Type {
          case g.OctetString:
              fmt.Printf("string: %s\n", string(variable.Value.([]byte)))
          default:
              fmt.Printf("number: %d\n", g.ToBigInt(variable.Value))
          }
      }
  }
  
  func main() {
      defer elapsed("snmp")()
      snmpRead()
  }
  </code></pre>
  
  <p>Out:</p>
  
  <pre><code>start
  0: oid: .1.3.6.1.2.1.33.1.2.7.0 number: 21
  snmp took 3.668148ms
  </code></pre>
  
  <p>30x faster than <code>pysnmp</code></p>
  
  <hr>
  
  <p>I need to the asynchronous performance which <code>go-routine</code> populated <code>asyncio</code> in <em>Python3</em>. </p>
  
  <p>So, is this means that I should migrate from <code>pysnmp</code> to <code>gosnmp</code>? </p>