for迴圈生成批量測試資料

2021-09-28 23:38:41 字數 1446 閱讀 8816

前言:配合大資料組生成測試資料,做測試使用,第一次運用遞迴的方式生成的資料用例使用體驗不友好:速度慢,消耗記憶體。於是第二次修改了遞迴拼接字串的方法,修改為時間複雜度更低的for迴圈來操作,僅僅使用了16秒就生成了y一億條資料。

static string newline =

"\r\n"

;// windows下換行符號

static stringbuffer sbrnew =

newstringbuffer

(1000000);

// 建立sbrnew

static

int count =1;

public

static

void

main

(string[

] args)

throws exception

else

} bufferedwriter.

close()

;// 關閉輸出流

long endtime = system.

currenttimemillis()

; system.err.

println(+

(endtime -starttime)

+"ms");

}

/**

* count 當前起始數量,

* clazz 組裝名稱,可按照需求改寫

* name 第二個字段,也可自定義

* 拼接不重要,內容隨時可以更改,所以傳參也沒有要求。

*/public

static stringbuffer getjoinstr

(int count, string clazz, string name)

// system.out.println("第" + count +"次進入");

return sbr;

}

/**

* @param flag 條件

* @param count 計數器

* @param first 是否首次進入

*/public

static stringbuffer getjoinstr

(boolean flag,

int count,

int first)

system.out.

println

("第"

+ count +

"次進入");

if(flag)

else

count++

;return

joiningstr

(flag,count,0)

;}

Oracle批量生成測試資料方法

一 test windos方式 declare maxrecords constant int 1000 i int 1 begin for i in 1.maxrecords loop insert into test2 id,name values test2 seq.nextval,to ch...

測試資料生成

目的 sql server 搭建日誌傳輸,模擬災難轉移,在主庫上不斷生成測試資料,模擬生產環境。生成測試資料指令碼 表結構 if table dbo.t1 exists,then drop it if object id dbo.t1 u is not null drop table dbo.t1 ...

Oracle123 自動批量生成測試資料

背景 系統需要改進pt,針對資料庫效能需要模擬線上百萬級資料量。參考 直接生成資料 插入大量資料 生成唯一guid sample1 select rownum as id,to char sysdate rownum 24 3600,yyyy mm dd hh24 mi ss as inc date...