Skip to content

Instantly share code, notes, and snippets.

View hpcx82's full-sized avatar

hpcx hpcx82

  • Shanghai
View GitHub Profile
@hpcx82
hpcx82 / generate.lua
Created November 9, 2012 12:42 — forked from chenshuo/query_freq.cc
Sort queries by their frequencies.
-- this version is very slow, as every time we update the buffer, we creating a new string, which
-- makes the original buffer unreferenced. and lua's gc will kicks in often to clean up memory
-- which is really realy slow.
local file = io.open("file.txt", "w")
local buffer = ''
for i = 1, 500000000 do
local n = i % math.random(10000)
local str = string.format("This is a number %d\n", n)
buffer = buffer .. str -- make the original string buffer unreferenced
if i % 10000 == 0 then
// The code below would print overlapped A and B sequences like:
// ...
// A
// A
// B
// B
// ...
//
// Please add multi-threading protection code to make sure that
// As and Bs are printed in the order of: