Test of the insertion speed of MongoDB and PostgreSQL under Golang

Source: Internet
Author: User
Tags stmt

Recently read an article, said that PostgreSQL also supports NOSQL, defined the exclusive JSONB data type, and faster than MongoDB, and today verified the next, the same data, postgre insertion speed is only MONGO of three points. may be caused by their respective drivers.

data structure: type Stockdaystruct{Date int32 O, H, L, C, V, a Float32}mongo used the MGO package, the insertion code is as follows: Func READHQ (conn net. Conn, C*mgo. Collection, Codestring) {    varBUF [ -]byte    varx Stockvary kline_day forI: =0; ; i++{_, Err:= Conn. Read (buf[0: -])        ifErr = =io. EOF {fmt. Println ("end of this file transfer")             Break        }        ifErr! =Nil {fmt. PRINTLN (ERR)return} b_buf:= bytes. Newbuffer (buf[0: -]) binary. Read (b_buf, Binary. Littleendian,&X)//binary. Littleendian is the concept of in-memory byte-order, which is to put low-byte into the back. Network transmission is generally used Bigendian, memory byte sequence and CPU, programming to convert. Y.code =Code y.a=x.a y.c=x.c y.date=x.date Y.H=X.H Y.L=X.L y.o=X.O y.v=X.V//FMT. Println (y)Err = C.insert (&y)ifErr! =Nil {panic (err)}}return} #postgresql Table structure CREATE TABLE json_test (ID serial not NULL, data jsonb, CONSTRAINT json_test_pkey PRIMARY KEY (ID) ) used the"GITHUB.COM/LIB/PQ"This package: Insert code: FUNC READHQ (conn net. Conn, DB*sql. DB, Codestring) {    varBUF [ -]byte    varx Stockday for{_, Err:= Conn. Read (buf[0: -])        ifErr = =io. EOF {fmt. Println ("end of this file transfer")             Break        }        ifErr! =Nil {fmt. PRINTLN (ERR)return} b_buf:= bytes. Newbuffer (buf[0: -]) binary. Read (b_buf, Binary. Littleendian,&X)//binary. Littleendian is the concept of in-memory byte-order, which is to put low-byte into the back.        Network transmission is generally used Bigendian, memory byte sequence and CPU, programming to convert. //FMT. Println (y)//err = C.insert (&y)BUF, err: = json. Marshal (&x)//Inserting Datastmt, err: = db. Prepare ("INSERT into Json_test (data) VALUES ($) Returning ID") Checkerr (Err) _, Err= stmt. Exec (string(BUF)) Checkerr (err)}return}

Test of the insertion speed of MongoDB and PostgreSQL under Golang

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.