From 09b0d436d378db7e52ae00a0a5c592b90ff8d8f2 Mon Sep 17 00:00:00 2001 From: Cecil Singh <54638818+Cecilsingh@users.noreply.github.com> Date: Thu, 5 Sep 2024 15:23:18 +1000 Subject: [PATCH] Create memoryUsage.R --- memoryHandling/memoryUsage.R | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 memoryHandling/memoryUsage.R diff --git a/memoryHandling/memoryUsage.R b/memoryHandling/memoryUsage.R new file mode 100644 index 0000000..d56d7a8 --- /dev/null +++ b/memoryHandling/memoryUsage.R @@ -0,0 +1,31 @@ +#The rep() function is used to repeate +#The value to be repeated is the number 1 +#1e9 is the scientific notation for one billion + +firstHalfMem <- rep(1, 1e9) + +secondHalfMem <- rep(1, 1e9) + +#additionalMem <- rep(1, 1e8) + +#Measures the time taken for a specific block of code to execute, in this case, a for loop +#The tictoc package provides functions to measure time +#tictoc::tic() starts the timer and records the current time which is used to measure the duration of code execution +#The for loop iterates 100 times +#tictoc::toc() stops the timer +#tic() shows how long the code inside tic() and toc() calls took to execute +library(tictoc) + +tictoc::tic() + +for (i in 1:100){ + j=i+1 + #gc() +} + +tictoc::toc() + + +#rm(firstHalfMem) + +#gc()