<commit_before>const BUFFERS = false

var leveldown = require('..')
  , crypto    = require('crypto')
  , putCount  = 0
  , getCount  = 0
  , rssBase
  , db

function run () {
  var key = 'long key to test memory usage ' + String(Math.floor(Math.random() * 10000000))

  if (BUFFERS) key = new Buffer(key)

  db.get(key, function (err, value) {
    getCount++

    if (err) {
      var putValue = crypto.randomBytes(1024)
      if (!BUFFERS) putValue = putValue.toString('hex')

      return db.put(key, putValue, function () {
        putCount++
        process.nextTick(run)
      })
    }

    process.nextTick(run)
  })

  if (getCount % 1000 === 0) {
    gc()
    console.log(
        'getCount ='
      , getCount
      , ', putCount = '
      , putCount
      , ', rss ='
      , Math.round(process.memoryUsage().rss / rssBase * 100) + '%'
      , Math.round(process.memoryUsage().rss / 1024 / 1024) + 'M'
      , JSON.stringify([0,1,2,3,4,5,6].map(function (l) {
          return db.getProperty('leveldb.num-files-at-level' + l)
        }))<commit_msg>qualify 'gc()' use<commit_after>const BUFFERS = false

var leveldown = require('..')
  , crypto    = require('crypto')
  , putCount  = 0
  , getCount  = 0
  , rssBase
  , db

function run () {
  var key = 'long key to test memory usage ' + String(Math.floor(Math.random() * 10000000))

  if (BUFFERS) key = new Buffer(key)

  db.get(key, function (err, value) {
    getCount++

    if (err) {
      var putValue = crypto.randomBytes(1024)
      if (!BUFFERS) putValue = putValue.toString('hex')

      return db.put(key, putValue, function () {
        putCount++
        process.nextTick(run)
      })
    }

    process.nextTick(run)
  })

  if (getCount % 1000 === 0) {
    if (typeof gc != 'undefined')
      gc()
    console.log(
        'getCount ='
      , getCount
      , ', putCount = '
      , putCount
      , ', rss ='
      , Math.round(process.memoryUsage().rss / rssBase * 100) + '%'
      , Math.round(process.memoryUsage().rss / 1024 / 1024) + 'M'
      , JSON.stringify([0,1,2,3,4,5,6].map(function (l) {
          return db.getProperty('leveldb.num-files-at-level' + l)
        }))
{'fraction_non_alphanumeric': 0.16288755205923183, 'fraction_numerical': 0.03424340583063397, 'mean_word_length': 2.3261538461538462, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 2, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1735360', 'n_tokens_mistral': 822, 'n_tokens_neox': 751, 'n_words': 156}