Re: List and String concatenation speed.
Kostirya <[email protected]> Tue, 30 Aug 2016 16:07:50 +0300
| Newsgroups | gmane.comp.lang.ml.mlton.user |
|---|---|
| Message-ID | <CAG+QnTc1+TGLqhGApaopiH0ON6vfLSsNjeSZkd65dwd-GQf3nQ@mail.gmail.com> |
Hello.
I've decided to use FFI for String.^.
However, the speed has not been increased (slowed down, in fact).
The code is lower. I think I've done everything properly?
C:
#include <sys/types.h>
#include <string.h>
void string_concat_memmove(void *dst, const void *src1, size_t len1, const
void *src2, size_t len2) {
memmove(dst, src1, len1);
dst += len1;
memmove(dst, src2, len2);
return;
}
SML:
val string_concat_memmove = _import "string_concat_memmove" :
Word8.word array * string * int * string * int -> unit;
fun op ^ (a: string, b: string): string =
let
val a_length = String.size a
and b_length = String.size b
in
if a_length = 0 then b else
if b_length = 0 then a else
let
val arr = Word8Array.array(a_length + b_length, 0w0)
in
string_concat_memmove(arr, a, a_length, b, b_length);
Byte.bytesToString (Word8Array.vector arr)
end
end
Best Regards.
Nick.
2016-08-29 16:46 GMT+03:00 Kostirya <[email protected]>:
> Yes. Poly/ML use memmove to to implement String.^
>
>
> 2016-08-29 16:21 GMT+03:00 Matthew Fluet <[email protected]>:
>
>> >> poly --script string_concat.sml
>> > 0.462269
>> >
>> >> mlton string_concat.sml && ./string_concat
>> > 2.713323
>>
>> It looks like Poly/ML uses memmove to implement String.^, which would
>> be more efficient for character sequences.
>>
>
>
--
You received this message because you are subscribed to the Google Groups "MLton-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
------------------------------------------------------------------------------
_______________________________________________
MLton-user mailing list
[email protected]; [email protected]
https://lists.sourceforge.net/lists/listinfo/mlton-user