assignperf.Rout.save 24 KB
Newer Older
Radford Neal's avatar
Radford Neal committed
1

2
pqR version 2.15.1 (2018-00-00), based on R 2.15.0 (2012-03-30)
Radford Neal's avatar
Radford Neal committed
3

4
R 2.15.0 is Copyright (C) 2012 The R Foundation for Statistical Computing
Radford Neal's avatar
Radford Neal committed
5 6
ISBN 3-900051-07-0

7
Modifications to R in pqR are Copyright (C) 2013-2018 Radford M. Neal
8 9

Some modules are from R-2.15.1 or later versions distributed by the R Core Team
Radford Neal's avatar
Radford Neal committed
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24

Platform: x86_64-unknown-linux-gnu (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

25

26
No helper threads, task merging enabled, uncompressed pointers.
27

28 29 30 31
> # Test performance of complex assignments, and other stuff, by seeing
> # what storage allocation is done.
> 
> options(keep.source=FALSE)  # avoid allocations for source references
Radford Neal's avatar
Radford Neal committed
32 33 34 35 36
> 
> print(1)  # get some stuff allocated before Rprofmemt activatived.
[1] 1
> 
> vsize <- 100  # must be multiple of 4
37
> Rprofmemt(nelem=vsize,bytes=FALSE)
Radford Neal's avatar
Radford Neal committed
38
> 
39
> 
Radford Neal's avatar
Radford Neal committed
40 41 42
> # One-level assignments.
> 
> a <- numeric(vsize)
43
RPROFMEM: (double 100):"numeric" 
Radford Neal's avatar
Radford Neal committed
44 45 46 47 48 49 50 51
> a[10] <- 3        # shouldn't duplicate
> a[[11]] <- 4      # shouldn't duplicate
> print(a)
  [1] 0 0 0 0 0 0 0 0 0 3 4 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
 [38] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
 [75] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
> 
> a <- c(list(a=4,b=FALSE),rep(list(7),vsize-2))
52 53
RPROFMEM: (list 100):
RPROFMEM: (character 100):
Radford Neal's avatar
Radford Neal committed
54 55 56 57
> a$b <- TRUE       # shouldn't duplicate
> a[10] <- 3        # shouldn't duplicate
> a[[11]] <- 4      # shouldn't duplicate
> print(unlist(a))
58 59
RPROFMEM: (double 100):"unlist" "print" 
RPROFMEM: (character 100):"unlist" "print" 
Radford Neal's avatar
Radford Neal committed
60 61 62 63 64 65 66
a b                                                                             
4 1 7 7 7 7 7 7 7 3 4 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 
                                                                                
7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 
                                        
7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 
> 
67
> a <- c(list(a=4,b=FALSE),rep(list(7),vsize-2))
68 69
RPROFMEM: (list 100):
RPROFMEM: (character 100):
70
> names(a) <- NULL  # shouldn't duplicate
Radford Neal's avatar
Radford Neal committed
71
> print(unlist(a))
72
RPROFMEM: (double 100):"unlist" "print" 
73
  [1] 4 0 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7
Radford Neal's avatar
Radford Neal committed
74 75 76 77
 [38] 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7
 [75] 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7
> 
> a <- numeric(vsize)
78
RPROFMEM: (double 100):"numeric" 
Radford Neal's avatar
Radford Neal committed
79 80
> b <- a
> a[[3]] <- -1      # will have to duplicate
81
RPROFMEM: (double 100):
Radford Neal's avatar
Radford Neal committed
82 83 84 85 86 87 88 89 90 91 92 93 94
> b[[4]] <- -2      # shouldn't duplicate
> print(a)
  [1]  0  0 -1  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
 [26]  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
 [51]  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
 [76]  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
> print(b)
  [1]  0  0  0 -2  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
 [26]  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
 [51]  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
 [76]  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
> 
> a <- numeric(vsize)
95
RPROFMEM: (double 100):"numeric" 
Radford Neal's avatar
Radford Neal committed
96
> n <- paste0("xx",1:vsize)
97 98
RPROFMEM: (integer 100):"paste0" 
RPROFMEM: (character 100):"paste0" 
Radford Neal's avatar
Radford Neal committed
99 100
> names(a) <- n     # shouldn't duplicate numeric part, might duplicate names
> 
101 102
> e <- new.env()
> v <- numeric(vsize)
103
RPROFMEM: (double 100):"numeric" 
104 105 106 107
> e$a <- v          # shouldn't duplicate
> 
> a <- 1
> v <- numeric(vsize)
108
RPROFMEM: (double 100):"numeric" 
109
> attr(a,"fred") <- v  # shouldn't duplicate, but does currently
110
RPROFMEM: (double 100):
111 112
> 
> 
Radford Neal's avatar
Radford Neal committed
113 114 115
> # Two-level assignments.
> 
> a <- rep(list(a=1,b=1:vsize,c="xx",d="yy"),vsize/4)
116 117 118
RPROFMEM: (integer 100):
RPROFMEM: (list 100):
RPROFMEM: (character 100):
Radford Neal's avatar
Radford Neal committed
119
> a$b[3] <- 99L     # will need to duplicate, because of repeated elements
120
RPROFMEM: (integer 100):
Radford Neal's avatar
Radford Neal committed
121
> print(a$b+1000L)  # don't pass a$b itself, since affects NAMEDCNT
122
RPROFMEM: (integer 100):"print" 
Radford Neal's avatar
Radford Neal committed
123 124 125 126 127 128 129 130 131
  [1] 1001 1002 1099 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015
 [16] 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030
 [31] 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045
 [46] 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060
 [61] 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075
 [76] 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090
 [91] 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100
> a$b[3] <- 99L     # shouldn't duplicate now
> print(a$b+1000L)
132
RPROFMEM: (integer 100):"print" 
Radford Neal's avatar
Radford Neal committed
133 134 135 136 137 138 139 140 141 142 143 144 145 146
  [1] 1001 1002 1099 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015
 [16] 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030
 [31] 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045
 [46] 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060
 [61] 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075
 [76] 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090
 [91] 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100
> print(a[[6]])     # should still be 1:vsize
  [1]   1   2   3   4   5   6   7   8   9  10  11  12  13  14  15  16  17  18
 [19]  19  20  21  22  23  24  25  26  27  28  29  30  31  32  33  34  35  36
 [37]  37  38  39  40  41  42  43  44  45  46  47  48  49  50  51  52  53  54
 [55]  55  56  57  58  59  60  61  62  63  64  65  66  67  68  69  70  71  72
 [73]  73  74  75  76  77  78  79  80  81  82  83  84  85  86  87  88  89  90
 [91]  91  92  93  94  95  96  97  98  99 100
147
> a$b[4] <- 99.1    # will have to coerce to real, shouldn't duplicate int vec
148
RPROFMEM: (double 100):
Radford Neal's avatar
Radford Neal committed
149
> print(a$b+1000)
150
RPROFMEM: (double 100):"print" 
151
  [1] 1001.0 1002.0 1099.0 1099.1 1005.0 1006.0 1007.0 1008.0 1009.0 1010.0
Radford Neal's avatar
Radford Neal committed
152 153 154 155 156 157 158 159 160
 [11] 1011.0 1012.0 1013.0 1014.0 1015.0 1016.0 1017.0 1018.0 1019.0 1020.0
 [21] 1021.0 1022.0 1023.0 1024.0 1025.0 1026.0 1027.0 1028.0 1029.0 1030.0
 [31] 1031.0 1032.0 1033.0 1034.0 1035.0 1036.0 1037.0 1038.0 1039.0 1040.0
 [41] 1041.0 1042.0 1043.0 1044.0 1045.0 1046.0 1047.0 1048.0 1049.0 1050.0
 [51] 1051.0 1052.0 1053.0 1054.0 1055.0 1056.0 1057.0 1058.0 1059.0 1060.0
 [61] 1061.0 1062.0 1063.0 1064.0 1065.0 1066.0 1067.0 1068.0 1069.0 1070.0
 [71] 1071.0 1072.0 1073.0 1074.0 1075.0 1076.0 1077.0 1078.0 1079.0 1080.0
 [81] 1081.0 1082.0 1083.0 1084.0 1085.0 1086.0 1087.0 1088.0 1089.0 1090.0
 [91] 1091.0 1092.0 1093.0 1094.0 1095.0 1096.0 1097.0 1098.0 1099.0 1100.0
161
> a$b[5] <- 99.7    # shouldn't duplicate now
Radford Neal's avatar
Radford Neal committed
162
> print(a$b+1000)
163
RPROFMEM: (double 100):"print" 
164
  [1] 1001.0 1002.0 1099.0 1099.1 1099.7 1006.0 1007.0 1008.0 1009.0 1010.0
Radford Neal's avatar
Radford Neal committed
165 166 167 168 169 170 171 172 173 174
 [11] 1011.0 1012.0 1013.0 1014.0 1015.0 1016.0 1017.0 1018.0 1019.0 1020.0
 [21] 1021.0 1022.0 1023.0 1024.0 1025.0 1026.0 1027.0 1028.0 1029.0 1030.0
 [31] 1031.0 1032.0 1033.0 1034.0 1035.0 1036.0 1037.0 1038.0 1039.0 1040.0
 [41] 1041.0 1042.0 1043.0 1044.0 1045.0 1046.0 1047.0 1048.0 1049.0 1050.0
 [51] 1051.0 1052.0 1053.0 1054.0 1055.0 1056.0 1057.0 1058.0 1059.0 1060.0
 [61] 1061.0 1062.0 1063.0 1064.0 1065.0 1066.0 1067.0 1068.0 1069.0 1070.0
 [71] 1071.0 1072.0 1073.0 1074.0 1075.0 1076.0 1077.0 1078.0 1079.0 1080.0
 [81] 1081.0 1082.0 1083.0 1084.0 1085.0 1086.0 1087.0 1088.0 1089.0 1090.0
 [91] 1091.0 1092.0 1093.0 1094.0 1095.0 1096.0 1097.0 1098.0 1099.0 1100.0
> a[[10]][2] <- 40L # will need to duplicate, because of repeated elements
175
RPROFMEM: (integer 100):
Radford Neal's avatar
Radford Neal committed
176
> print(a[[10]]+1000L)
177
RPROFMEM: (integer 100):"print" 
Radford Neal's avatar
Radford Neal committed
178 179 180 181 182 183 184 185 186
  [1] 1001 1040 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015
 [16] 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030
 [31] 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045
 [46] 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060
 [61] 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075
 [76] 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090
 [91] 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100
> a[[10]][2] <- 40L # shouldn't duplicate now
> print(a[[10]]+1000L)
187
RPROFMEM: (integer 100):"print" 
Radford Neal's avatar
Radford Neal committed
188 189 190 191 192 193 194 195 196
  [1] 1001 1040 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015
 [16] 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030
 [31] 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045
 [46] 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060
 [61] 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075
 [76] 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090
 [91] 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100
> 
> a <- c(list(x=c(0,y=1,rep(0,vsize-2))),rep(list("a"),vsize-1))
197 198 199 200
RPROFMEM: (double 100):
RPROFMEM: (character 100):
RPROFMEM: (list 100):
RPROFMEM: (character 100):
Radford Neal's avatar
Radford Neal committed
201 202
> a$x[2] <- 12      # shouldn't duplicate
> print(a$x+1000)
203
RPROFMEM: (double 100):"print" 
Radford Neal's avatar
Radford Neal committed
204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219
        y                                                                       
1000 1012 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 
                                                                                
1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 
                                                                                
1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 
                                                                                
1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 
                                                                                
1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 
                                                                                
1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 
                    
1000 1000 1000 1000 
> a$x[[2]] <- 13    # shouldn't duplicate
> print(a$x+1000)
220
RPROFMEM: (double 100):"print" 
Radford Neal's avatar
Radford Neal committed
221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236
        y                                                                       
1000 1013 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 
                                                                                
1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 
                                                                                
1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 
                                                                                
1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 
                                                                                
1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 
                                                                                
1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 
                    
1000 1000 1000 1000 
> a$x["y"] <- 14    # shouldn't duplicate
> print(a$x+1000)
237
RPROFMEM: (double 100):"print" 
Radford Neal's avatar
Radford Neal committed
238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253
        y                                                                       
1000 1014 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 
                                                                                
1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 
                                                                                
1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 
                                                                                
1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 
                                                                                
1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 
                                                                                
1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 
                    
1000 1000 1000 1000 
> a$x[["y"]] <- 15  # shouldn't duplicate
> print(a$x+1000)
254
RPROFMEM: (double 100):"print" 
Radford Neal's avatar
Radford Neal committed
255 256 257 258 259 260 261 262 263 264 265 266 267 268 269
        y                                                                       
1000 1015 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 
                                                                                
1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 
                                                                                
1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 
                                                                                
1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 
                                                                                
1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 
                                                                                
1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 
                    
1000 1000 1000 1000 
> 
270 271
> e <- new.env()
> e$a <- numeric(vsize)
272
RPROFMEM: (double 100):"numeric" 
273 274 275
> e$a[2] <- 9       # shouldn't duplicate
> e$b <- e$a        # shouldn't duplicate
> e$a[3] <- 2       # should duplicate
276
RPROFMEM: (double 100):
277 278 279
> e$a[[4]] <- 3     # shouldn't duplicate
> e$c <- e$b        # shouldn't duplicate
> e$c[[5]] <- 4     # should duplicate
280
RPROFMEM: (double 100):
281 282 283 284 285 286 287 288 289 290 291 292 293 294
> print(e$a)
  [1] 0 9 2 3 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
 [38] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
 [75] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
> print(e$b)
  [1] 0 9 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
 [38] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
 [75] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
> print(e$c)
  [1] 0 9 0 0 4 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
 [38] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
 [75] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
> 
> L <- c (list (new.env()), rep(list(1),vsize-1))
295
RPROFMEM: (list 100):
296
> v <- numeric(vsize)
297
RPROFMEM: (double 100):"numeric" 
298 299 300 301
> L[[1]]$a <- v     # shouldn't duplicate
> 
> e <- new.env()
> e$a <- numeric(vsize)
302
RPROFMEM: (double 100):"numeric" 
303 304 305
> e$a[2] <- 9       # shouldn't duplicate
> e$b <- e$a        # shouldn't duplicate
> e$a[3] <- 2       # should duplicate
306
RPROFMEM: (double 100):
307 308 309
> e$a[[4]] <- 3     # shouldn't duplicate
> e$c <- e$b
> e$c[[5]] <- 4     # should duplicate
310
RPROFMEM: (double 100):
311 312 313 314 315 316 317 318 319 320 321 322 323 324 325
> print(e$a)
  [1] 0 9 2 3 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
 [38] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
 [75] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
> print(e$b)
  [1] 0 9 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
 [38] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
 [75] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
> print(e$c)
  [1] 0 9 0 0 4 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
 [38] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
 [75] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
> 
> a <- 1
> v <- numeric(vsize)
326
RPROFMEM: (double 100):"numeric" 
327
> attr(a,"fred") <- v     # shouldn't duplicate, but does currently
328
RPROFMEM: (double 100):
329
> attr(a,"fred")[2] <- 3  # should duplicate
330
RPROFMEM: (double 100):
331
> attr(a,"fred")[3] <- 4  # shouldn't duplicate, but does currently
332
RPROFMEM: (double 100):
333 334 335 336 337 338 339 340 341 342 343
> print(a)
[1] 1
attr(,"fred")
  [1] 0 3 4 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
 [38] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
 [75] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
> print(v)
  [1] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
 [38] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
 [75] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
> 
Radford Neal's avatar
Radford Neal committed
344
> a <- numeric(vsize)
345
RPROFMEM: (double 100):"numeric" 
Radford Neal's avatar
Radford Neal committed
346
> n <- paste0("xx",1:vsize)
347 348
RPROFMEM: (integer 100):"paste0" 
RPROFMEM: (character 100):"paste0" 
349
> names(a) <- n     # shouldn't duplicate numeric part, maybe dup names
350
> names(a)[2] <- "q"# shouldn't duplicate anything, but currently dups chars twice
351
RPROFMEM: (character 100):
Radford Neal's avatar
Radford Neal committed
352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368
> print(a)
  xx1     q   xx3   xx4   xx5   xx6   xx7   xx8   xx9  xx10  xx11  xx12  xx13 
    0     0     0     0     0     0     0     0     0     0     0     0     0 
 xx14  xx15  xx16  xx17  xx18  xx19  xx20  xx21  xx22  xx23  xx24  xx25  xx26 
    0     0     0     0     0     0     0     0     0     0     0     0     0 
 xx27  xx28  xx29  xx30  xx31  xx32  xx33  xx34  xx35  xx36  xx37  xx38  xx39 
    0     0     0     0     0     0     0     0     0     0     0     0     0 
 xx40  xx41  xx42  xx43  xx44  xx45  xx46  xx47  xx48  xx49  xx50  xx51  xx52 
    0     0     0     0     0     0     0     0     0     0     0     0     0 
 xx53  xx54  xx55  xx56  xx57  xx58  xx59  xx60  xx61  xx62  xx63  xx64  xx65 
    0     0     0     0     0     0     0     0     0     0     0     0     0 
 xx66  xx67  xx68  xx69  xx70  xx71  xx72  xx73  xx74  xx75  xx76  xx77  xx78 
    0     0     0     0     0     0     0     0     0     0     0     0     0 
 xx79  xx80  xx81  xx82  xx83  xx84  xx85  xx86  xx87  xx88  xx89  xx90  xx91 
    0     0     0     0     0     0     0     0     0     0     0     0     0 
 xx92  xx93  xx94  xx95  xx96  xx97  xx98  xx99 xx100 
    0     0     0     0     0     0     0     0     0 
369 370 371 372 373 374 375 376 377 378 379 380 381 382
> print(n)
  [1] "xx1"   "xx2"   "xx3"   "xx4"   "xx5"   "xx6"   "xx7"   "xx8"   "xx9"  
 [10] "xx10"  "xx11"  "xx12"  "xx13"  "xx14"  "xx15"  "xx16"  "xx17"  "xx18" 
 [19] "xx19"  "xx20"  "xx21"  "xx22"  "xx23"  "xx24"  "xx25"  "xx26"  "xx27" 
 [28] "xx28"  "xx29"  "xx30"  "xx31"  "xx32"  "xx33"  "xx34"  "xx35"  "xx36" 
 [37] "xx37"  "xx38"  "xx39"  "xx40"  "xx41"  "xx42"  "xx43"  "xx44"  "xx45" 
 [46] "xx46"  "xx47"  "xx48"  "xx49"  "xx50"  "xx51"  "xx52"  "xx53"  "xx54" 
 [55] "xx55"  "xx56"  "xx57"  "xx58"  "xx59"  "xx60"  "xx61"  "xx62"  "xx63" 
 [64] "xx64"  "xx65"  "xx66"  "xx67"  "xx68"  "xx69"  "xx70"  "xx71"  "xx72" 
 [73] "xx73"  "xx74"  "xx75"  "xx76"  "xx77"  "xx78"  "xx79"  "xx80"  "xx81" 
 [82] "xx82"  "xx83"  "xx84"  "xx85"  "xx86"  "xx87"  "xx88"  "xx89"  "xx90" 
 [91] "xx91"  "xx92"  "xx93"  "xx94"  "xx95"  "xx96"  "xx97"  "xx98"  "xx99" 
[100] "xx100"
> 
383
> a <- numeric(vsize)
384
RPROFMEM: (double 100):"numeric" 
385
> b <- integer(vsize)
386
RPROFMEM: (integer 100):"integer" 
387
> attr(a,"bert") <- b     # shouldn't duplicate, but does currently
388
RPROFMEM: (integer 100):
389
> attr(a,"bert")[2] <- 7L # shouldn't duplicate, but does currently
390
RPROFMEM: (integer 100):
391 392 393 394 395 396 397 398
> print(a)
  [1] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
 [38] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
 [75] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
attr(,"bert")
  [1] 0 7 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
 [38] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
 [75] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
399
> 
400
> 
401 402 403 404
> # Three-level assignments.
> 
> a <- c(list (q = c(list (x = rep(3,vsize)), rep(list(1),vsize-1))),
+        rep(list(2),vsize-1))
405 406 407 408 409
RPROFMEM: (double 100):
RPROFMEM: (list 100):
RPROFMEM: (character 100):
RPROFMEM: (list 100):
RPROFMEM: (character 100):
410 411 412
> 
> a[[1]]$x[2] <- 9     # shouldn't duplicate
> a$q$x[vsize+2] <- 8  # should allocate for extension, not dup higher levels
413
RPROFMEM: (double 102):
414 415 416 417 418 419 420 421
> 
> print(a$q$x)
  [1]  3  9  3  3  3  3  3  3  3  3  3  3  3  3  3  3  3  3  3  3  3  3  3  3  3
 [26]  3  3  3  3  3  3  3  3  3  3  3  3  3  3  3  3  3  3  3  3  3  3  3  3  3
 [51]  3  3  3  3  3  3  3  3  3  3  3  3  3  3  3  3  3  3  3  3  3  3  3  3  3
 [76]  3  3  3  3  3  3  3  3  3  3  3  3  3  3  3  3  3  3  3  3  3  3  3  3  3
[101] NA  8
> 
Radford Neal's avatar
Radford Neal committed
422
> 
423 424 425 426
> # Slot assignments.
> 
> Rprofmemt(NULL)
> setClass ("george", representation(a="numeric",b="logical"))
427
> Rprofmemt(nelem=vsize,bytes=FALSE)
428 429
> 
> ia <- rep(1.2,vsize)
430
RPROFMEM: (double 100):
431
> ib <- rep(c(TRUE,FALSE),length=vsize)
432
RPROFMEM: (logical 100):
433 434
> 
> x <- new ("george", a=ia+1, b=ib)
435 436 437
RPROFMEM: (double 100):"initialize" "initialize" "new" 
RPROFMEM: (double 100):"initialize" "initialize" "new" 
RPROFMEM: (logical 100):"initialize" "initialize" "new" 
438 439
> 
> v <- seq.int(1/vsize,1,length=vsize)
440
RPROFMEM: (double 100):
441
> x@a <- v      # shouldn't duplicate, but currently dups three things
442
RPROFMEM: (double 100):
443
> x@a[2] <- 9   # shouldn't duplicate, but currently dups four things
444
RPROFMEM: (double 100):
445
> x@b[3] <- NA  # should duplicate at most one, but currently dups four things
446
RPROFMEM: (logical 100):
447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470
> 
> Rprofmemt(NULL)
> print(x)
An object of class "george"
Slot "a":
  [1] 0.01 9.00 0.03 0.04 0.05 0.06 0.07 0.08 0.09 0.10 0.11 0.12 0.13 0.14 0.15
 [16] 0.16 0.17 0.18 0.19 0.20 0.21 0.22 0.23 0.24 0.25 0.26 0.27 0.28 0.29 0.30
 [31] 0.31 0.32 0.33 0.34 0.35 0.36 0.37 0.38 0.39 0.40 0.41 0.42 0.43 0.44 0.45
 [46] 0.46 0.47 0.48 0.49 0.50 0.51 0.52 0.53 0.54 0.55 0.56 0.57 0.58 0.59 0.60
 [61] 0.61 0.62 0.63 0.64 0.65 0.66 0.67 0.68 0.69 0.70 0.71 0.72 0.73 0.74 0.75
 [76] 0.76 0.77 0.78 0.79 0.80 0.81 0.82 0.83 0.84 0.85 0.86 0.87 0.88 0.89 0.90
 [91] 0.91 0.92 0.93 0.94 0.95 0.96 0.97 0.98 0.99 1.00

Slot "b":
  [1]  TRUE FALSE    NA FALSE  TRUE FALSE  TRUE FALSE  TRUE FALSE  TRUE FALSE
 [13]  TRUE FALSE  TRUE FALSE  TRUE FALSE  TRUE FALSE  TRUE FALSE  TRUE FALSE
 [25]  TRUE FALSE  TRUE FALSE  TRUE FALSE  TRUE FALSE  TRUE FALSE  TRUE FALSE
 [37]  TRUE FALSE  TRUE FALSE  TRUE FALSE  TRUE FALSE  TRUE FALSE  TRUE FALSE
 [49]  TRUE FALSE  TRUE FALSE  TRUE FALSE  TRUE FALSE  TRUE FALSE  TRUE FALSE
 [61]  TRUE FALSE  TRUE FALSE  TRUE FALSE  TRUE FALSE  TRUE FALSE  TRUE FALSE
 [73]  TRUE FALSE  TRUE FALSE  TRUE FALSE  TRUE FALSE  TRUE FALSE  TRUE FALSE
 [85]  TRUE FALSE  TRUE FALSE  TRUE FALSE  TRUE FALSE  TRUE FALSE  TRUE FALSE
 [97]  TRUE FALSE  TRUE FALSE

471
> Rprofmemt(nelem=vsize,bytes=FALSE)
472
> 
473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489
> 
> # Things that should use VARIANT_UNCLASS, VARIANT_ANY_ATTR, or
> # VARIANT_ANY_ATTR_EX_DIM, and hence avoid some unnecessary copying.
> 
> vsize <- 11
> 
> Rprofmemt(NULL)
> 
> a <- numeric(vsize)
> names(a) <- rep("a",vsize)
> 
> B <- matrix(1.1,vsize,vsize)
> attr(B,"fred") <- rep("a",vsize)
> 
> o <- (1:vsize) + 0.5
> class(o) <- "abc"
> 
490
> Rprofmemt(nelem=vsize,bytes=FALSE)
491 492 493 494 495 496 497 498 499 500 501 502 503 504
> 
> for (i in a) print (i)
[1] 0
[1] 0
[1] 0
[1] 0
[1] 0
[1] 0
[1] 0
[1] 0
[1] 0
[1] 0
[1] 0
> for (i in exp(a)) print (i)
505
RPROFMEM: (double 11):
506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530
[1] 1
[1] 1
[1] 1
[1] 1
[1] 1
[1] 1
[1] 1
[1] 1
[1] 1
[1] 1
[1] 1
> 
> for (i along a) print (i)
[1] 1
[1] 2
[1] 3
[1] 4
[1] 5
[1] 6
[1] 7
[1] 8
[1] 9
[1] 10
[1] 11
> for (i along exp(a)) print(i)
531
RPROFMEM: (double 11):
532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556
[1] 1
[1] 2
[1] 3
[1] 4
[1] 5
[1] 6
[1] 7
[1] 8
[1] 9
[1] 10
[1] 11
> 
> for (i across B) print (i)
[1] 1
[1] 2
[1] 3
[1] 4
[1] 5
[1] 6
[1] 7
[1] 8
[1] 9
[1] 10
[1] 11
> for (i across exp(B)) print (i)
557
RPROFMEM: (double 121):
558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576
[1] 1
[1] 2
[1] 3
[1] 4
[1] 5
[1] 6
[1] 7
[1] 8
[1] 9
[1] 10
[1] 11
> 
> print(sum(a))
[1] 0
> print(sum(exp(a)))
[1] 11
> print(prod(a))
[1] 0
> print(prod(exp(a)))
577
RPROFMEM: (double 11):"print" 
578 579
[1] 1
> 
580 581 582
> print(length(a))
[1] 11
> print(length(exp(a)))
583
RPROFMEM: (double 11):"print" 
584 585 586 587 588 589 590 591 592 593 594 595 596
[1] 11
> 
> print(length(o))
[1] 11
> print(length(unclass(o)))
[1] 11
> 
> length.abc <- function (x) 123
> 
> print(length(o))
[1] 123
> print(length(unclass(o)))
[1] 11
Radford Neal's avatar
Radford Neal committed
597
>