【问题标题】:Optimize mapping an array优化映射数组
【发布时间】:2021-01-05 02:43:43
【问题描述】:

我有 125k 测试用例,需要 1 分 30 秒才能得到结果。有什么选项可以优化我的映射吗?谢谢。。

 const getEachValueByLine = () => {
    if (IsJsonString(multipleValue)) {
      setInvalidFormat(true)
      isValidRegex ? setValidRegex(true) : setValidRegex(false)
      const parseValue = Object.entries(JSON.parse(multipleValue))
      const addId = parseValue.map((item, index) => ({ id: index, case: item[0], expected: item[1] }))
      handleMultiValidate(addId)
    } else {
      setInvalidFormat(false)
    }
  }

问题从这里开始:

const parseValue = Object.entries(JSON.parse(multipleValue))
const addId = parseValue.map((item, index) => ({ id: index, case: item[0], expected: item[1] }))

【问题讨论】:

  • 此链接将解决您的问题。使用这个Link

标签: javascript arrays reactjs


【解决方案1】:

你试过big-json吗?

const fs = require('fs');
const path = require('path');
const json = require('big-json');
 
const readStream = fs.createReadStream('big.json');
const parseStream = json.createParseStream();
 
parseStream.on('data', function(pojo) {
    // => receive reconstructed POJO
});
 
readStream.pipe(parseStream);

【讨论】:

  • 这个怎么用?我只需要将getEachValueByLine 代码放到receive reconstructed POJO 中吗?
  • parseStream.on(multipleValue, function(pojo) { // your code }); 这样使用
猜你喜欢
  • 2020-07-21
  • 2020-07-20
  • 2016-01-29
  • 1970-01-01
  • 1970-01-01
  • 2016-06-28
  • 2020-01-31
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多