Added you implementation in my bench but got an index out of bound
(Fatal error: exception Invalid_argument("index out of bounds", here:

    let compare i =
      let rec compare' j =
        if j >= sublen then true
        else if str.[i+j] <> sub.[j] then false
                  ^^^^^^^
        else compare' (j+1)
      in
      compare' 0
    in