Skip to content

Use of CMOV instruction in Levenshtein's minimum function #50

@eos175

Description

@eos175

The min function used in the Levenshtein distance algorithm can be improved by using the CMOV instruction instead of conditional jumps. The updated function produces better performance than the original min function.

link: https://gcc.godbolt.org/z/EazrW9zKb

func min2(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func min3(a, b, c int) int {
    return min2(min2(a, b), c)
}

link: https://gcc.godbolt.org/z/EazrW9zKb

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions