caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] [OCAML]:: the cost of List.length
@ 2013-04-14 13:23 沈胜宇
  2013-04-14 13:32 ` Malcolm Matalka
  0 siblings, 1 reply; 4+ messages in thread
From: 沈胜宇 @ 2013-04-14 13:23 UTC (permalink / raw)
  To: caml-list

[-- Attachment #1: Type: text/plain, Size: 255 bytes --]

Dear all:


I have a program that run very fast.


Recently, I add a call to List.length to this old program's inner loop, which make it significantly slower.


So what is the cost of List.length, is it liner to the size of the list? or is a const?


Shen

[-- Attachment #2: Type: text/html, Size: 347 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Caml-list] [OCAML]:: the cost of List.length
  2013-04-14 13:23 [Caml-list] [OCAML]:: the cost of List.length 沈胜宇
@ 2013-04-14 13:32 ` Malcolm Matalka
  2013-04-15  6:29   ` David House
  0 siblings, 1 reply; 4+ messages in thread
From: Malcolm Matalka @ 2013-04-14 13:32 UTC (permalink / raw)
  To: 沈胜宇; +Cc: caml-list

[-- Attachment #1: Type: text/plain, Size: 355 bytes --]

O(n)
Den 14 apr 2013 15:27 skrev "沈胜宇" <syshen@nudt.edu.cn>:

> Dear all:
>
> I have a program that run very fast.
>
> Recently, I add a call to List.length to this old program's inner loop,
> which make it significantly slower.
>
> So what is the cost of List.length, is it liner to the size of the list?
> or is a const?
>
> Shen
>

[-- Attachment #2: Type: text/html, Size: 666 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Caml-list] [OCAML]:: the cost of List.length
  2013-04-14 13:32 ` Malcolm Matalka
@ 2013-04-15  6:29   ` David House
  2013-04-15 11:05     ` 沈胜宇
  0 siblings, 1 reply; 4+ messages in thread
From: David House @ 2013-04-15  6:29 UTC (permalink / raw)
  To: Malcolm Matalka; +Cc: 沈胜宇, caml-list

Lists are naive linked lists, i.e. either the empty list or a pair of
an element and a list. Finding the length means walking to the end of
the list.

There is probably a better data structure than lists for your
purposes. What operations do you need, and which ones need to be fast?

On 14 April 2013 14:32, Malcolm Matalka <mmatalka@gmail.com> wrote:
> O(n)
>
> Den 14 apr 2013 15:27 skrev "沈胜宇" <syshen@nudt.edu.cn>:
>
>> Dear all:
>>
>> I have a program that run very fast.
>>
>> Recently, I add a call to List.length to this old program's inner loop,
>> which make it significantly slower.
>>
>> So what is the cost of List.length, is it liner to the size of the list?
>> or is a const?
>>
>> Shen

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Re: [Caml-list] [OCAML]:: the cost of List.length
  2013-04-15  6:29   ` David House
@ 2013-04-15 11:05     ` 沈胜宇
  0 siblings, 0 replies; 4+ messages in thread
From: 沈胜宇 @ 2013-04-15 11:05 UTC (permalink / raw)
  To: David House; +Cc: Malcolm Matalka, caml-list

Dear all:

I have found that the slow down of my program is not caused by the List.length directly, instead, the list length operation cause some different change in my control flow, that is the direct cause of my slow down.

but still thank you for your help.

Shen


> -----原始邮件-----
> 发件人: "David House" <dhouse@janestreet.com>
> 发送时间: 2013-04-15 14:29:21 (星期一)
> 收件人: "Malcolm Matalka" <mmatalka@gmail.com>
> 抄送: "沈胜宇" <syshen@nudt.edu.cn>, caml-list <caml-list@inria.fr>
> 主题: Re: [Caml-list] [OCAML]:: the cost of List.length
> 
> Lists are naive linked lists, i.e. either the empty list or a pair of
> an element and a list. Finding the length means walking to the end of
> the list.
> 
> There is probably a better data structure than lists for your
> purposes. What operations do you need, and which ones need to be fast?
> 
> On 14 April 2013 14:32, Malcolm Matalka <mmatalka@gmail.com> wrote:
> > O(n)
> >
> > Den 14 apr 2013 15:27 skrev "沈胜宇" <syshen@nudt.edu.cn>:
> >
> >> Dear all:
> >>
> >> I have a program that run very fast.
> >>
> >> Recently, I add a call to List.length to this old program's inner loop,
> >> which make it significantly slower.
> >>
> >> So what is the cost of List.length, is it liner to the size of the list?
> >> or is a const?
> >>
> >> Shen


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2013-04-15 11:08 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-04-14 13:23 [Caml-list] [OCAML]:: the cost of List.length 沈胜宇
2013-04-14 13:32 ` Malcolm Matalka
2013-04-15  6:29   ` David House
2013-04-15 11:05     ` 沈胜宇

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).