অ-ভেক্টরাইজড বিকল্পগুলির সময় পারফরম্যান্স সম্পর্কে আমি কৌতূহল ছিলাম। এই উদ্দেশ্যে, আমি knguyen দ্বারা সংজ্ঞায়িত f ফাংশনটি ব্যবহার করেছি
f <- function(x, output) {
wellName <- x[1]
plateName <- x[2]
wellID <- 1
print(paste(wellID, x[3], x[4], sep=","))
cat(paste(wellID, x[3], x[4], sep=","), file= output, append = T, fill = T)
}
এবং তার উদাহরণের মতো ডেটাফ্রেম:
n = 100; #number of rows for the data frame
d <- data.frame( name = LETTERS[ sample.int( 25, n, replace=T ) ],
plate = paste0( "P", 1:n ),
value1 = 1:n,
value2 = (1:n)*10 )
বিড়ালের () পদ্ধতির সাথে একটি রাইট.টেবিল () এর সাথে তুলনা করার জন্য আমি দুটি ভেক্টরিযুক্ত ফাংশন (অন্যদের চেয়ে দ্রুত নিশ্চিত করার জন্য) অন্তর্ভুক্ত করেছি ...
library("ggplot2")
library( "microbenchmark" )
library( foreach )
library( iterators )
tm <- microbenchmark(S1 =
apply(d, 1, f, output = 'outputfile1'),
S2 =
for(i in 1:nrow(d)) {
row <- d[i,]
# do stuff with row
f(row, 'outputfile2')
},
S3 =
foreach(d1=iter(d, by='row'), .combine=rbind) %dopar% f(d1,"outputfile3"),
S4= {
print( paste(wellID=rep(1,n), d[,3], d[,4], sep=",") )
cat( paste(wellID=rep(1,n), d[,3], d[,4], sep=","), file= 'outputfile4', sep='\n',append=T, fill = F)
},
S5 = {
print( (paste(wellID=rep(1,n), d[,3], d[,4], sep=",")) )
write.table(data.frame(rep(1,n), d[,3], d[,4]), file='outputfile5', row.names=F, col.names=F, sep=",", append=T )
},
times=100L)
autoplot(tm)
ফলস্বরূপ চিত্রটি দেখায় যে প্রয়োগটি একটি নন-ভেক্টরাইজড সংস্করণটির জন্য সেরা পারফরম্যান্স দেয়, যেখানে Writ.table () বিড়ালটিকে ছাড়িয়ে গেছে বলে মনে হয় ()।
