github.com/igggame/nebulas-go@v2.1.0+incompatible/nbre/benchmark/common/serialize.cpp (about)

     1  // Copyright (C) 2018 go-nebulas authors
     2  //
     3  // This file is part of the go-nebulas library.
     4  //
     5  // the go-nebulas library is free software: you can redistribute it and/or
     6  // modify
     7  // it under the terms of the GNU General Public License as published by
     8  // the Free Software Foundation, either version 3 of the License, or
     9  // (at your option) any later version.
    10  //
    11  // the go-nebulas library is distributed in the hope that it will be useful,
    12  // but WITHOUT ANY WARRANTY; without even the implied warranty of
    13  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    14  // GNU General Public License for more details.
    15  //
    16  // You should have received a copy of the GNU General Public License
    17  // along with the go-nebulas library.  If not, see
    18  // <http://www.gnu.org/licenses/>.
    19  //
    20  #include "benchmark/benchmark_instances.h"
    21  #include "common/byte.h"
    22  #include "common/math.h"
    23  #include "fs/proto/ir.pb.h"
    24  #include <ff/network.h>
    25  #include <iostream>
    26  
    27  define_nt(name, std::string);
    28  define_nt(version, uint64_t);
    29  define_nt(height, uint64_t);
    30  define_nt(ir, std::string);
    31  define_nt(ir_type, std::string);
    32  
    33  typedef ff::net::ntpackage<1, name, version, height, ir, ir_type> my_ir_t;
    34  
    35  BENCHMARK(ir_size, proto) {
    36    nbre::NBREIR ni;
    37    ni.set_name("nebulas");
    38    ni.set_version(0xffffffffffffffff);
    39    ni.set_height(0xffffffffffffffff);
    40    ni.set_ir("testnet1987");
    41    ni.set_ir_type("llvm");
    42    auto bytes_long = ni.ByteSizeLong();
    43    std::cout << "proto bytes: " << bytes_long << std::endl;
    44    neb::bytes rs(bytes_long);
    45    ni.SerializeToArray((void *)rs.value(), rs.size());
    46  }
    47  
    48  BENCHMARK(ir_size, nt) {
    49    my_ir_t mi;
    50    mi.set<name>("nebulas");
    51    mi.set<version>(0xffffffffffffffff);
    52    mi.set<height>(0xffffffffffffffff);
    53    mi.set<ir>("testnet");
    54    mi.set<ir_type>("llvm");
    55    ff::net::marshaler lr(ff::net::marshaler::length_retriver);
    56    mi.arch(lr);
    57    auto bytes_long = lr.get_length();
    58    char *buf = new char[bytes_long];
    59    std::cout << "nt bytes: " << bytes_long << std::endl;
    60    ff::net::marshaler tr(buf, bytes_long, ff::net::marshaler::seralizer);
    61    mi.arch(tr);
    62  }
    63