`JSON.stringify` vs `isEqual`

Benchmark created on


Setup

const user1 = {
  user: {
    id: 42,
    name: "Jane Doe",
    isActive: true,
    roles: ["admin", "editor", "user"],
    profile: {
      age: 34,
      email: "jane.doe@example.com",
      address: {
        street: "123 Main St",
        city: "Metropolis",
        zip: "12345",
        geo: {
          lat: 40.7128,
          lng: -74.006,
        },
      },
      preferences: {
        theme: "dark",
        notifications: {
          email: true,
          sms: false,
          push: true,
        },
        languages: ["en", "es", "fr"],
      },
    },
    projects: [
      {
        id: "p1",
        name: "Project Alpha",
        status: "active",
        tags: ["react", "typescript"],
        contributors: [
          { id: 1, name: "Alice", role: "developer" },
          { id: 2, name: "Bob", role: "designer" },
        ],
        tasks: [
          {
            id: "t1",
            title: "Setup repo",
            completed: true,
            due: null,
          },
          {
            id: "t2",
            title: "Implement feature X",
            completed: false,
            due: "2024-07-01",
          },
        ],
      },
      {
        id: "p2",
        name: "Project Beta",
        status: "archived",
        tags: [],
        contributors: [],
        tasks: [],
      },
    ],
    activityLog: [
      {
        timestamp: "2024-06-01T10:00:00Z",
        action: "login",
        details: { ip: "192.168.1.1", device: "desktop" },
      },
      {
        timestamp: "2024-06-02T14:30:00Z",
        action: "update_profile",
        details: { field: "email", oldValue: "old@example.com", newValue: "jane.doe@example.com" },
      },
    ],
  },
  settings: {
    version: 3,
    features: {
      beta: ["featureA", "featureB"],
      enabled: {
        dashboard: true,
        analytics: false,
        export: true,
      },
    },
    limits: {
      maxProjects: 10,
      maxUsers: 100,
      storage: {
        totalGB: 50,
        usedGB: 12.5,
      },
    },
  },
  notifications: [
    {
      id: "n1",
      type: "message",
      read: false,
      content: {
        title: "Welcome!",
        body: "Thanks for joining our platform.",
      },
      createdAt: "2024-06-01T09:00:00Z",
    },
    {
      id: "n2",
      type: "reminder",
      read: true,
      content: {
        title: "Complete your profile",
        body: "Add more details to get personalized recommendations.",
      },
      createdAt: "2024-06-02T11:15:00Z",
    },
  ],
  stats: {
    logins: 27,
    uploads: 14,
    lastActive: "2024-06-03T16:45:00Z",
    usage: [
      { date: "2024-06-01", minutes: 45 },
      { date: "2024-06-02", minutes: 30 },
      { date: "2024-06-03", minutes: 60 },
    ],
  }
}

const user2 = {
  id: "u2",
  name: "Jordan Smith",
  email: "jordan.smith@example.com",
  preferences: {
    theme: "light",
    language: "fr",
    features: {
      beta: ["featureC"],
      enabled: {
        dashboard: false,
        analytics: true,
        export: false,
        reports: true,
      },
    },
    limits: {
      maxProjects: 5,
      maxUsers: 50,
      storage: {
        totalGB: 20,
        usedGB: 7,
        warningThresholdGB: 15,
      },
    },
  },
  notifications: [
    {
      id: "n3",
      type: "alert",
      read: false,
      content: {
        title: "Security Notice",
        body: "Please update your password.",
        action: "Update Now",
      },
      createdAt: "2024-06-04T08:30:00Z",
    },
    {
      id: "n4",
      type: "update",
      read: false,
      content: {
        title: "New Feature Released",
        body: "Try out the new reports section.",
        link: "/features/reports",
      },
      createdAt: "2024-06-05T10:00:00Z",
    },
  ],
  stats: {
    logins: 12,
    uploads: 3,
    lastActive: "2024-06-05T18:20:00Z",
    usage: [
      { date: "2024-06-04", minutes: 20, actions: 5 },
      { date: "2024-06-05", minutes: 35, actions: 8 },
    ],
    streak: 2,
  }
}

Test runner

Ready to run.

Testing in
TestOps/sec
Lodash isEqual
const result = _.isEqual(user1, user2)
ready
stringify
const result = JSON.stringify(user1) === JSON.stringify(user2)

ready

Revisions

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