Skip to content

BinaryDiff could be much faster #3193

@matthiaskraaz

Description

@matthiaskraaz

org.assertj.core.internal.BinaryDiff could be much faster

  • assertj core version: 3.24.2
  • java version: Java 11
  • test framework version: JUnit 5

Test case reproducing the bug

Path expected = ...
Path actual = ...
assertThat(actual).hasSameBinaryContentAs(expected);

Solution

Change implementation as follows:

public BinaryDiffResult diff(Path actual, byte[] expected) throws IOException {
  try(InputStream actualStream = new BufferedInputStream(Files.newInputStream(actual))) {
    return diff(actualStream, expected);
  }
}

(add BufferedInputStream)

Resulting speedup for 2,5MB: from 8 sec down to 0.2 sec.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions