[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Mldonkey-users] [patch #4510] IP: Save Memory by using chars instead of
From: |
pango |
Subject: |
[Mldonkey-users] [patch #4510] IP: Save Memory by using chars instead of int |
Date: |
Thu, 13 Oct 2005 10:43:16 +0200 |
User-agent: |
Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7.8) Gecko/20050831 Galeon/1.3.20 (Debian package 1.3.20-1) |
Follow-up Comment #8, patch #4510 (project mldonkey):
Several things;
* The type of t1, t2, t3 are records (of one field each, but records
nonetheless). That's not exactly the same thing, and in this case it even
matters:
# size_w (0, 1, 2, 3) ;;
- : int = 5
# type t = { a: int*int*int*int } ;;
# size_w { a = (0, 1, 2, 3) } ;;
- : int = 7
(I just saw that's you're testing both later on... Ok)
* the use of @ to append elements at the end of lists silently makes your
algorithm complexity raise to O(n^2), using around 500000 steps to add your
1000 elements. Try always adding elements at the head of lists, using
List.rev as a last step if order matters (n*2 steps is still better than
n*n/2)
* beware of aliasing. It's non-trivial to guess when it happens.
# let lt1 = ref [] and lt2 = ref [] ;;
# for i = 1 to 1000 do
lt1 := Int32.of_int 3 :: !lt1;
lt2 := 3l :: !lt2;
done ;;
# size_w !lt1 ;;
- : int = 4000
# size_w !lt2 ;;
- : int = 3001
(In that case, it's the use of the function Int32.of_int that forces each
element to be rebuilt, preventing aliasing.)
* my results:
# open Size ;;
# let nlist f n =
let rec nlist_aux acc n =
if n = 0 then List.rev acc
else nlist_aux (f () :: acc) (n-1) in
nlist_aux [] n ;;
val nlist : (unit -> 'a) -> int -> 'a list = <fun>
# (* for reference *)
# size_w (nlist (fun () -> ()) 1000) ;;
- : int = 3000
# size_w (nlist (fun () -> Random.int 256, Random.int 256, Random.int 256,
Random.int 256) 1000) ;;
- : int = 8000
# size_w (nlist (fun () -> Random.int 65536, Random.int 65536) 1000) ;;
- : int = 6000
# size_w (nlist (fun () -> Random.int32 Int32.max_int) 1000) ;;
- : int = 4000
# size_w (nlist (fun () -> char_of_int (Random.int 256), char_of_int
(Random.int 256), char_of_int (Random.int 256), char_of_int (Random.int 256))
1000) ;;
- : int = 8000
I'm still skeptic about the results of that library...
_______________________________________________________
Reply to this item at:
<http://savannah.nongnu.org/patch/?func=detailitem&item_id=4510>
_______________________________________________
Message posté via/par Savannah
http://savannah.nongnu.org/
- [Mldonkey-users] [patch #4510] IP: Save Memory by using chars instead of int, bogeyman, 2005/10/11
- [Mldonkey-users] [patch #4510] IP: Save Memory by using chars instead of int, anonymous, 2005/10/11
- [Mldonkey-users] [patch #4510] IP: Save Memory by using chars instead of int, anonymous, 2005/10/11
- [Mldonkey-users] [patch #4510] IP: Save Memory by using chars instead of int, pango, 2005/10/12
- [Mldonkey-users] [patch #4510] IP: Save Memory by using chars instead of int, pango, 2005/10/12
- [Mldonkey-users] [patch #4510] IP: Save Memory by using chars instead of int, anonymous, 2005/10/12
- [Mldonkey-users] [patch #4510] IP: Save Memory by using chars instead of int, pango, 2005/10/12
- [Mldonkey-users] [patch #4510] IP: Save Memory by using chars instead of int, anonymous, 2005/10/13
- [Mldonkey-users] [patch #4510] IP: Save Memory by using chars instead of int,
pango <=
- [Mldonkey-users] [patch #4510] IP: Save Memory by using chars instead of int, anonymous, 2005/10/13
- [Mldonkey-users] [patch #4510] IP: Save Memory by using chars instead of int, bogeyman, 2005/10/13
- [Mldonkey-users] [patch #4510] IP: Save Memory by using chars instead of int, spiralvoice, 2005/10/16
- [Mldonkey-users] [patch #4510] IP: Save Memory by using chars instead of int, spiralvoice, 2005/10/27