---
# System prepended metadata

title: 210426 記憶體耗能測試結果

---

# 210426 記憶體耗能測試結果

[TOC]

## 測試流程

+ 每 5 秒紀錄 RAM 大小到 log 檔。
+ 開 3 個 Terminal 同步處理

1. 程式開始，載入所需物件
2. 載入檔案
3. 分析檔案中 10 則訊息
4. Garbage Collection
5. 回到 3.，直到處理共 **250** 則訊息
6. 程式結束

### Code
```python
import gc

gc.enable()

times = 0
msg_file_list = ['2019_Apr-Jul_Data']
for msg_file in msg_file_list:
    with open(msg_file + '.csv', 'r', encoding="utf-8") as f:
        csv_list = preprocess_from_csv_to_list(f)
        i = 0
        start = 0
        window = 10
        size = len(csv_list)
        while start < size and start < 2500:
            start = i * window
            end = (i + 1) * window
            print(datetime.now().strftime("%Y/%m/%d %H:%M:%S") + ', ' + msg_file + ' ' + f'{i:04d}')
            csv_df = model.batch_analysis(csv_list[start: end], pinyin_mode=True)
            save_path = 'data/' + msg_file + f'{i:04d}' + '_result.csv'
            csv_df.to_csv(save_path, index=False)
            i += 1
            times += 1
            # garbage collection
            gc.collect() 
        f.close()

```

## 測試機器
+ **CPU:** i7-6700
+ **RAM:** 16G
+ **GPU:** Null

## 測試結果

### 1. 沒有GC
![](https://i.imgur.com/wlgYQwi.png)

### 2. 有GC
![](https://i.imgur.com/eYE2dBB.png)

