晚上跟數學系的朋友聊幾句,他用個公式算出合法的帳號數字(滿合理的遠大於台灣人口數),於似乎,來用鳥鳥暴力解試試,並且練一下 golang 的 goroutine 用法。當然最後的資料個數是一樣的,共有 5.2億組。總數公式 = 26 (字母) * 2 (男女) * 10^7 (最後一碼是校正碼,只有七種變化)
只是我用暴力解,偷懶用多層 loop 發一下波動拳 XD 理論上還可以優化最後一碼用算的,而不是用暴力算,在一台老電腦上(3.1 GHz 雙核心Intel Core i7),大概花 1小時產出(包括每百萬筆寫到檔案)
最後的成果:
% go run main.go --verify A123456789A123456789 : PASS, time cost: 23.449µs% go run main.go --verify A123456780A123456780 : FAIL, time cost: 25.528µs% time go run main.go --cpu 4...taskID: 0, taskCount: 1000000, totalCount: 510000000, timeCost: 57m56.195527594s, mem: 336 MBtaskID: 2, taskCount: 1000000, totalCount: 511000000, timeCost: 58m12.348436403s, mem: 286 MBtaskID: 1, taskCount: 1000000, totalCount: 512000000, timeCost: 58m17.794134191s, mem: 360 MBtaskID: 0, taskCount: 1000000, totalCount: 513000000, timeCost: 58m18.106069808s, mem: 380 MBtaskID: 2, taskCount: 1000000, totalCount: 514000000, timeCost: 58m33.170090521s, mem: 247 MBtaskID: 1, taskCount: 1000000, totalCount: 515000000, timeCost: 58m39.34318826s, mem: 308 MBtaskID: 0, taskCount: 1000000, totalCount: 516000000, timeCost: 58m39.902875471s, mem: 370 MBtaskID: 2, taskCount: 1000000, totalCount: 517000000, timeCost: 58m50.616989581s, mem: 133 MBtaskID: 1, taskCount: 1000000, totalCount: 518000000, timeCost: 58m55.655774417s, mem: 67 MBtaskID: 2, taskCount: 1000000, totalCount: 519000000, timeCost: 59m3.85291194s, mem: 111 MBtaskID: 2, taskCount: 1000000, totalCount: 520000000, timeCost: 59m14.91097006s, mem: 111 MBTotal verified IDs count: 520000000 , time cost: 59m18.802491746sgo run main.go --cpu 4 9320.09s user 3332.58s system 355% cpu 59:19.56 total% ls -lah /tmp/ids*-rw------- 1 user wheel 1.4G 8 27 08:41 /tmp/ids-0.txt-rw------- 1 user wheel 1.4G 8 27 08:41 /tmp/ids-1.txt-rw------- 1 user wheel 1.4G 8 27 08:42 /tmp/ids-2.txt-rw------- 1 user wheel 1.0G 8 27 08:28 /tmp/ids-3.txt% wc -l /tmp/ids-*140000000 /tmp/ids-0.txt140000000 /tmp/ids-1.txt140000000 /tmp/ids-2.txt100000000 /tmp/ids-3.txt520000000 total
沒有留言:
張貼留言