wxf666 最近的时间轴更新
wxf666

wxf666

V2EX 第 280897 号会员,加入于 2018-01-08 18:22:24 +08:00
今日活跃度排名 372
wxf666 最近回复了
1 天前
回复了 MegatronKing 创建的主题 推广 买断制上线,一天的营收超过一个月
Deepin 20 ,打开时报错说 libstdc++.so.6 版本太低诶。。

```
/usr/share/reqable/reqable: /lib/x86_64-linux-gnu/libstdc++.so.6: version `GLIBCXX_3.4.26' not found (required by /usr/share/reqable/lib/libdesktop_multi_window_plugin.so)
/usr/share/reqable/reqable: /lib/x86_64-linux-gnu/libstdc++.so.6: version `GLIBCXX_3.4.26' not found (required by /usr/share/reqable/lib/libreqable_appdump_plugin.so)
```
1 天前
回复了 zyb201314 创建的主题 JavaScript 求助一个正则表达式.
```js
s = 'txt=123,txt=kg66vv,hhj,txt=6966,ggg'
s.match(/(?<=(?:^|,)[^=]+=)([^,]*6[^,]*)(?=,|$)/g)
```
@luozic #6 感觉 DuckDB 读文件时,性能有点问题?


感觉 DuckDB 读空缓冲区后,Writer 才能继续写。写满后,DuckDB 才去读一样?

同样的内容,会因喂给 DuckDB 的姿势不同,表现出不同的速度差异。。

就像 Python 的假多线程一样,只能有一个线程活跃。。

2 天前
回复了 ComplexPug 创建的主题 程序员 关于一个经典海量数据的问题
@ComplexPug #14 我用 Lua 写了个(可限制内存)词频统计,并和 DuckDB 比了下速度,感觉还行。


1. 测试数据

[知乎回答]( https://www.zhihu.com/answer/1906560411 ) 里,分享的《英文维基百科(仅文本版)》,并简单用脚本预处理了下(去标点、每词一行、转小写)。

解压后:13.33 GB
处理后:12.84 GB ,23 亿词(不重复的有 854W )


2. 测试结果

- DuckDB (不限制内存):4 分半( 1.0X )
- Lua(最多存100M文本):7 分半( 1.6X ),01 个共 103MB 临时文件
- Lua(最多存 10M文本):8 分钟( 1.7X ),23 个共 306MB 临时文件


3. 测试硬件:i5-8250U 低压 CPU 轻薄本。。


4. 运行截图




5. 预处理脚本

```shell
unzip -p enwiki_text.zip | tr -cs "[:alnum:]'-" '\n' | tr [:upper:] [:lower:]
```


6. Lua 脚本( V 站吞空格,所以将行首缩进,都转为全角空格了)

```lua
#!luajit
local TOP_NUM = 1000
local MAX_SIZE = tonumber(arg[1] or 16) * 2 ^ 20

local dict = {}
local dict_size = 0
local files = {}
local words = {}
local word = ''
local freq = 0

function heap_swap(heap, comp, lhs, rhs, func, next)
  if comp(heap[lhs], heap[rhs]) then
   heap[lhs], heap[rhs] = heap[rhs], heap[lhs]
   func(heap, comp, next)
  end
end

function heap_up(heap, comp, idx)
  if idx > 1 then
   local pa = math.floor(idx / 2)
   heap_swap(heap, comp, idx, pa, heap_up, pa)
  end
end

function heap_down(heap, comp, idx)
  if idx <= #heap / 2 then
   local left, right = idx * 2, idx * 2 + 1
   local son = right > #heap and left or
   (comp(heap[left], heap[right]) and left or right)
   heap_swap(heap, comp, son, idx, heap_down, son)
  end
end

function heap_push(heap, comp, val)
  table.insert(heap, val)
  heap_up(heap, comp, #heap)
end

function heap_pop(heap, comp)
  heap[1] = heap[#heap]
  table.remove(heap)
  heap_down(heap, comp, 1)
end

function heap_adjust(heap, comp, idx)
  heap_down(heap, comp, idx)
  heap_up(heap, comp, idx)
end

function comp(lhs, rhs)
  return lhs[1] < rhs[1]
end

function sorted_keys(dict)
  local keys = {}
  for k in pairs(dict) do
   table.insert(keys, k)
  end
  table.sort(keys)
  return keys
end

function push_word()
  if #word > 0 then
   if #words < TOP_NUM then
    heap_push(words, comp, {freq, word})
   elseif freq > words[1][1] then
    words[1] = {freq, word}
    heap_adjust(words, comp, 1)
   end
  end
end

function try_save_dict(new_key)
  dict_size = dict_size + (new_key and #new_key or 0)
  if not new_key or dict_size > MAX_SIZE then
   local file = io.tmpfile()
   for idx, key in ipairs(sorted_keys(dict)) do
    file:write(dict[key], ' ', key, '\n')
   end
   dict = {}
   file:seek('set')
   dict_size = new_key and #new_key
   table.insert(files, {'', 0, file})
  end
end

for word in io.lines() do
  dict[word] = (dict[word] or try_save_dict(word) or 0) + 1
end
try_save_dict()

while #files > 0 do
  local file, read_ok = files[1]
  if word == file[1] then
   freq = freq + file[2]
  else
   push_word()
   word, freq = file[1], file[2]
  end
  file[2], read_ok, file[1] = file[3]:read('n', 1, 'l');
 (read_ok and heap_adjust or heap_pop)(files, comp, 1)
end
push_word()

table.sort(words, comp)
for i = #words, 1, -1 do
  io.write(string.format('%d %s\n', words[i][1], words[i][2]))
end
```
2 天前
回复了 AoEiuV020JP 创建的主题 程序员 电脑内存都被谁占了
@AoEiuV020JP 总感觉,Win10+ 有内存泄漏。。

表现为,用了几天后,关闭所有程序,但系统还会吃很多内存。。(比如一半以上。。)

Win7 、XP ,好像没有这种现象。。
3 天前
回复了 wangpugod2003 创建的主题 程序员 讨论一道面试题啊(take home task)
@WoodsGao #27 题目的原文件,应该是十进制字符串吧。。

就算是二进制数据,也应该是 8 字节,俩 int32 呀。。

4 天前
回复了 wangpugod2003 创建的主题 程序员 讨论一道面试题啊(take home task)
@wangpugod2003 #2 楼主,我突然对你的 10GB 文件感兴趣。。


假设你 10GB 二十亿条,那平均每条 (10 << 30) / 2e9 = 5 字节,

去除空格、换行 2 字节,还剩 3 字节,你是怎么存得下 10 位数的 ID ,和几位数的 value 呢?


4 天前
回复了 wangpugod2003 创建的主题 程序员 讨论一道面试题啊(take home task)
@wxf666 #5 等会儿,我以为是,求出现最多次数的 ID 了。。

那你这个算法,应该没问题的呀?

4 天前
回复了 wangpugod2003 创建的主题 程序员 讨论一道面试题啊(take home task)
极端情况下,每个 ID 只出现一次,

你是要在内存里,保留整个 几百 GB 的 ID 吗?

关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   959 人在线   最高记录 6543   ·     Select Language
创意工作者们的社区
World is powered by solitude
VERSION: 3.9.8.5 · 18ms · UTC 22:08 · PVG 06:08 · LAX 15:08 · JFK 18:08
Developed with CodeLauncher
♥ Do have faith in what you're doing.