(Add pbc lua) C ++ _ lua_python with/without extension Performance Test (0.1 million serializetostring & parsefromstring)

Source: Internet
Author: User

A. Extension

C ++: 0.259 s

Lua: 6.136 s

Python: 15.874 s

C ++ is 23.6 times better than Lua -->

Lua is 2.58 times better than Python -->

B. Without Extension

C ++: 0.098 s

Lin Zhuo Yi protoc-gen-Lua: 1.788 s

Cloud wind PBC Lua: Message mode 0.585 S, pack mode0.187s

Python: 4.645 s

C ++ is 18.2 times better than Lua -->

Lua is 2.59 times better than Python -->

C ++ with extension, slow 2.64

Lua with extension, slow 3.43

Python with extension, slow 3.41

---------------------------------------------

Test environment: VMWare debian6, Time Function

GCC 4.4.5

Lua 5.1.4

Python 2.6.6

Protobuf 2.4.1

------------------ C ++ ------------------------------

#include "person.pb.h"#include <iostream>#include <stdio.h>//#include <windows.h>int main(int argc, char* argv[]){GOOGLE_PROTOBUF_VERIFY_VERSION;//printf("%s\n","hello");Person person;person.set_id(1000);person.set_name("Alice");person.set_email("Alice@example.com");/*Phone* pPhone1 = person.AddExtension(Phone::phones);pPhone1->set_num("2147483647");pPhone1->set_type(Phone_PHONE_TYPE_HOME);Phone* pPhone2 = person.AddExtension(Phone::phones);pPhone2->set_num("123456789");pPhone2->set_type(Phone_PHONE_TYPE_MOBILE);//int aaa = person.ExtensionSize(Phone::phones);//Phone pPhone3 = person.GetExtension(Phone::phones, 1);*/std::string data;Person personShow;//DWORD dwStart = GetTickCount();for(int i=0; i< 100000; i++){person.SerializeToString(&data);personShow.ParseFromString(data);}//DWORD dwUse = GetTickCount() - dwStart;//printf("%d\n",dwUse);google::protobuf::ShutdownProtobufLibrary();return 0;}

------------------------------------------- Lua ------------------------------------------

package.path = package.path .. ';../protobuf/?.lua'package.cpath = package.cpath .. ';../protobuf/?.so'require 'person_pb'local person= person_pb.Person()person.id = 1000person.name = "Alice"person.email = "Alice@example.com"--[[local home = person.Extensions[person_pb.Phone.phones]:add()home.num = "2147483647"home.type = person_pb.Phone.HOMElocal home2 = person.Extensions[person_pb.Phone.phones]:add()home2.num = "2147483647"home2.type = person_pb.Phone.MOBILE]]local msg = person_pb.Person()local datafor i=1, 100000 dodata = person:SerializeToString()msg:ParseFromString(data)end--print(msg)

---------------------------------------------- PBC Lua --------------------------------------

local protobuf = require "protobuf"addr = io.open("../../build/addressbook.pb","rb")buffer = addr:read "*a"addr:close()protobuf.register(buffer)local person = {name = "Alice",email = "Alice@example.com",id = 1000,--phone = {--{ number = "123456789" , type = "MOBILE" },--{ number = "87654321" , type = "HOME" },--}}local bufferlocal tfor i=1, 100000 do--buffer = protobuf.encode("tutorial.Person", person)-- t = protobuf.decode("tutorial.Person", buffer)buffer = protobuf.pack("tutorial.Person name id email","Alice",1000,"Alice@example.com")protobuf.unpack("tutorial.Person name id email", buffer )end--[[for k,v in pairs(t) doif type(k) == "string" thenprint(k,v)endendprint(t.phone[2].type)for k,v in pairs(t.phone[1]) doprint(k,v)end]]

--------------------------------------------- Python ------------------------------------------

#! /usr/bin/pythonimport person_pb2person = person_pb2.Person()person.id = 1000person.name = "Alice"person.email = "Alice@example.com"personMsg = person_pb2.Person()"""phone1 = person.Extensions[person_pb2.Phone.phones].add()phone1.num = "2147483647"phone1.type = person_pb2.Phone.HOMEphone2 = person.Extensions[person_pb2.Phone.phones].add()phone2.num = "2147483647"phone2.type = person_pb2.Phone.MOBILE"""for i in range(100000):    data = person.SerializeToString()    personMsg .ParseFromString(data)

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.