gnustep-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: The goal of GNUstep 1.0


From: David Ayers
Subject: Re: The goal of GNUstep 1.0
Date: Sun, 30 Oct 2005 17:13:08 +0100
User-agent: Mozilla Thunderbird 1.0.2 (X11/20051002)

Fred Kiefer schrieb:
> On the more down to the bits side, I would like to see a stable memory
> layout for all GUI classes. This has two aspects, we are still missing
> some ivars that will be needed for full OpenStep/Cocoa compliance. The
> other side is that we could use more bit fields to make these classes
> more compact. After a 1.0 release it will get pretty hard to change the
> memory usage of these classes, so we need to do it now.

I'm curious, if you have some measurements to show that using bit fields
is a good idea.  I have the feeling that -gui does not really create
enough instances for the compactness of these instances to outweigh the
performance hit due to the fact that the compiler actually has to
generate more code for accessing bit fields than more naturally aligned
ivars.

I've hacked into -base's Testing/benchmark a little test to show the
difference.  (Note I'm not planing to commit this, it was just a
convenient place to put it.)

Cheers,
David
? bitfields.patch
Index: benchmark.m
===================================================================
RCS file: /cvsroot/gnustep/gnustep/core/base/Testing/benchmark.m,v
retrieving revision 1.21
diff -u -r1.21 benchmark.m
--- benchmark.m 25 Sep 2005 17:36:14 -0000      1.21
+++ benchmark.m 30 Oct 2005 16:08:20 -0000
@@ -65,6 +65,71 @@
 }
 @end
 
address@hidden BitField : NSObject
+{
+  struct _bfield {
+    unsigned flag1:1;
+    unsigned flag2:1;
+    unsigned flag3:1;
+    unsigned flag4:1;
+    unsigned flag5:1;
+  } _flags;
+}
+-(BOOL)flag1;
+-(void)setFlag1:(BOOL)fl;
+-(BOOL)flag2;
+-(void)setFlag2:(BOOL)fl;
+-(BOOL)flag3;
+-(void)setFlag3:(BOOL)fl;
+-(BOOL)flag4;
+-(void)setFlag4:(BOOL)fl;
+-(BOOL)flag5;
+-(void)setFlag5:(BOOL)fl;
address@hidden
address@hidden BitField
+-(BOOL)flag1 { return _flags.flag1; }
+-(void)setFlag1:(BOOL)fl { _flags.flag1 = fl; };
+-(BOOL)flag2 { return _flags.flag2; }
+-(void)setFlag2:(BOOL)fl { _flags.flag2 = fl; };
+-(BOOL)flag3 { return _flags.flag3; }
+-(void)setFlag3:(BOOL)fl { _flags.flag3 = fl; };
+-(BOOL)flag4 { return _flags.flag4; }
+-(void)setFlag4:(BOOL)fl { _flags.flag4 = fl; };
+-(BOOL)flag5 { return _flags.flag5; }
+-(void)setFlag5:(BOOL)fl { _flags.flag5 = fl; };
address@hidden
address@hidden NoBitField : NSObject
+{
+  BOOL flag1;
+  BOOL flag2;
+  BOOL flag3;
+  BOOL flag4;
+  BOOL flag5;
+}
+-(BOOL)flag1;
+-(void)setFlag1:(BOOL)fl;
+-(BOOL)flag2;
+-(void)setFlag2:(BOOL)fl;
+-(BOOL)flag3;
+-(void)setFlag3:(BOOL)fl;
+-(BOOL)flag4;
+-(void)setFlag4:(BOOL)fl;
+-(BOOL)flag5;
+-(void)setFlag5:(BOOL)fl;
address@hidden
address@hidden NoBitField
+-(BOOL)flag1 { return flag1; }
+-(void)setFlag1:(BOOL)fl { flag1 = fl; };
+-(BOOL)flag2 { return flag2; }
+-(void)setFlag2:(BOOL)fl { flag2 = fl; };
+-(BOOL)flag3 { return flag3; }
+-(void)setFlag3:(BOOL)fl { flag3 = fl; };
+-(BOOL)flag4 { return flag4; }
+-(void)setFlag4:(BOOL)fl { flag4 = fl; };
+-(BOOL)flag5 { return flag5; }
+-(void)setFlag5:(BOOL)fl { flag5 = fl; };
address@hidden
+
 void
 bench_object()
 {
@@ -736,6 +801,43 @@
   AUTO_END;
 }
 
+void
+bench_bitfield()
+{
+  BitField *bf = [[[BitField alloc]init]autorelease];
+  NoBitField *nbf = [[[NoBitField alloc]init]autorelease];
+  unsigned i;
+
+  AUTO_START;
+
+  printf("bitfields\n");
+  START_TIMER;
+  for (i = 0; i < MAX_COUNT*10; i++)
+    {
+      [bf setFlag1: [bf flag1]];
+      [bf setFlag2: [bf flag2]];
+      [bf setFlag3: [bf flag3]];
+      [bf setFlag4: [bf flag4]];
+      [bf setFlag5: [bf flag5]];
+    }
+  END_TIMER;
+  PRINT_TIMER("bitfields \t\t\t\t");
+
+  START_TIMER;
+  for (i = 0; i < MAX_COUNT*10; i++)
+    {
+      [nbf setFlag1: [nbf flag1]];
+      [nbf setFlag2: [nbf flag2]];
+      [nbf setFlag3: [nbf flag3]];
+      [nbf setFlag4: [nbf flag4]];
+      [nbf setFlag5: [nbf flag5]];
+    }
+  END_TIMER;
+  PRINT_TIMER("no bitfields \t\t\t\t");
+  
+  AUTO_END;
+}
+
 int main(int argc, char *argv[], char **env)
 {
   id pool;
@@ -761,6 +863,11 @@
   bench_maptable();
   bench_date();
   bench_data();
+  bench_bitfield();
+  bench_bitfield();
+  bench_bitfield();
+  bench_bitfield();
+  bench_bitfield();
   AUTO_END;
   return 0;
 }

reply via email to

[Prev in Thread] Current Thread [Next in Thread]