model : 42
model name : Intel(R) Core(TM) i5-2450M cpu @ 2.50GHz
系统信息:Linux sec 3.5.0-45-generic #68~precise1-Ubuntu SMP Wed Dec 4 16:18:46 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux
node postgresql package:https://github.com/brianc/node-postgres
db/index.js部分:
var pg = require('pg'); var conString = "postgres://test:test@localhost/pgs"; exports.pg_exec = function(prepared_obj,cb){ pg.connect(conString,function(err,client,done) { if(err) { cb(err,{"rowCount":0}) return; } client.query(prepared_obj,result) { done(); cb(err,result); }); }); }
index.js部分
/** * Created by ty4z2008 on 14-1-19. */ var pg_exec = require("./db").pg_exec; (function(){ console.log('start pg_insert'); var rand_ship = new Array('韵达','EMS','顺丰','圆通','申通','韵达','UPS','中通','平邮'),rand_alp=new Array('A','B','C','D','E','F','G','H','I','J','K','L','M','N','P','Q','R','S','T','U','V','W','X','Y','Z','a','b','c','d','e','f','g','h','i','j','k','m','n','p','r','s','t','u','v','w','x','y','z','2','3','4','5','6','7','8','9'),rand_number=new Array(1,2,3,4,5,6,7,8,9,0),rand_add=new Array('支付宝','网银','货到付款','财付通','微信支付','其他'),rand_gender=new Array('男','女'),rand_state=new Array('交易成功','交易失败','发货中','交易取消','运输中'); var rand_ship_length=rand_ship.length,rand_alp_length=rand_alp.length,rand_number_length=rand_number.length,rand_add_length=rand_add.length,rand_state_length=rand_state.length,rand_gender_length=rand_gender.length; for(var i = 0; i < 50000; i++) { var n=Math.floor(Math.random()*rand_number_length),a=Math.floor(Math.random()*rand_alp_length),e=Math.floor(Math.random()*rand_add_length),s=Math.floor(Math.random()*rand_ship_length),st=Math.floor(Math.random()*rand_state_length),g=Math.floor(Math.random()*rand_gender_length),price=Math.floor(Math.random()*100); total_price=i+rand_number[n]+i; count=rand_number[n]+rand_number[n]+2; czipcode = i+rand_number[n] + i; gender=rand_gender[g]; shipping=rand_ship[s]; payment=rand_add[e]; consignee="consignee"+rand_alp[a]+i; caddr=rand_alp[a]+'caddr'+i; cphone='1'+i+rand_number[n]; cmessage="cmessage"+rand_alp[a]+i; ostate=rand_state[st]; pg_exec({ name:"insert",text:" INSERT INTO " + "orderinfo(total_price,price,count,otime,shipping,payment," + " consignee,gender,caddr,czipcode,cphone,cmessage,ostate)" + "VALUES($1,$2,$3,current_timestamp(2),$4,$5,$6,$7,$8,$9,$10,$11,$12)",values:[total_price,consignee,ostate]},function(err){ if(err){ console.log(err); return; } }); }; })();
sql部分:
@H_502_33@CREATE TYPE sex_enum AS ENUM('男','女');
完成执行时间大概花了1分钟左右
原文链接:https://www.f2er.com/postgresql/195900.html