测试结构运算符 (v3)

Revision 3 of this benchmark created on


Setup

const columns = [
        { field: "date", title: "日期" },
        { field: "name", title: "名称" },
        { field: "province", title: "省份" },
        { field: "city", title: "城市" },
        { field: "address", title: "地址" },
      ];
      const rows = Array.from({ length: 10000 }, () => ({
        date: "2016-05-03",
        name: "小美",
        province: "北京",
        city: "朝阳区",
        address: "北京市朝阳区望京东路四号",
      }));

Test runner

Ready to run.

Testing in
TestOps/sec
Object.assign#对象扩展运算符

        const result = columns.map((column, colIndex) => {
          const newRow = {
            sortNo: colIndex,
            value: {
              col0: {
                date: "2016-05-03",
                name: "小美",
                province: "北京",
                city: "朝阳区",
                address: "北京市朝阳区望京东路四号",
              },
            },
          };
          rows.forEach((row, index) => {
            Object.assign(newRow.value, {
              [`col${index + 1}`]: {
                order: null,
                ...row,
              },
            });
          });
          return newRow;
        });
ready
对象扩展运算符

        const result1 = columns.map((column, colIndex) => {
          const newRow = {
            sortNo: colIndex,
            value: {
              col0: {
                date: "2016-05-03",
                name: "小美",
                province: "北京",
                city: "朝阳区",
                address: "北京市朝阳区望京东路四号",
              },
            },
          };
          rows.forEach((row, index) => {
            newRow.value[`col${index + 1}`] = {
              order: null,
              ...row,
            };
          });
          return newRow;
        });
ready
对象平铺赋值

        const result = columns.map((column, colIndex) => {
          const newRow = {
            sortNo: colIndex,
            value: {
              col0: {
                date: "2016-05-03",
                name: "小美",
                province: "北京",
                city: "朝阳区",
                address: "北京市朝阳区望京东路四号",
              },
            },
          };
          rows.forEach((row, index) => {
            newRow.value[`col${index + 1}`] = {
              order: null,
              date: row.date,
              name: row.name,
              province: row.province,
              city: row.city,
              address: row.address,
            };
          });
          return newRow;
        });
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.