You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

154 lines
54 KiB

3 years ago
  1. {
  2. "cells": [
  3. {
  4. "cell_type": "code",
  5. "execution_count": 1,
  6. "id": "1b48863d",
  7. "metadata": {},
  8. "outputs": [],
  9. "source": [
  10. "library(ggplot2)\n",
  11. "library(reshape)"
  12. ]
  13. },
  14. {
  15. "cell_type": "code",
  16. "execution_count": 2,
  17. "id": "7e338f77",
  18. "metadata": {},
  19. "outputs": [],
  20. "source": [
  21. "sum1 <- function(m) {\n",
  22. " res = 0\n",
  23. " \n",
  24. " for(i in 1:dim(m)[1]) {\n",
  25. " for(j in 1:dim(m)[2]) {\n",
  26. " res <- res + m[i,j]\n",
  27. " }\n",
  28. " }\n",
  29. "\n",
  30. " return(res)\n",
  31. "}\n"
  32. ]
  33. },
  34. {
  35. "cell_type": "code",
  36. "execution_count": 3,
  37. "id": "be204fce",
  38. "metadata": {},
  39. "outputs": [],
  40. "source": [
  41. "sum2 <- function(m) {\n",
  42. " res = .C(\"sum2\"\n",
  43. " ,mtrx=as.double(m)\n",
  44. " ,m=as.integer(dim(m)[1])\n",
  45. " ,n=as.integer(dim(m)[2])\n",
  46. " ,res=as.double(0)\n",
  47. " )\n",
  48. "\n",
  49. " return(res$res)\n",
  50. "}"
  51. ]
  52. },
  53. {
  54. "cell_type": "code",
  55. "execution_count": 4,
  56. "id": "b470f59c",
  57. "metadata": {},
  58. "outputs": [],
  59. "source": [
  60. "dyn.load(\"sum2.so\")"
  61. ]
  62. },
  63. {
  64. "cell_type": "code",
  65. "execution_count": 7,
  66. "id": "d8c35f6e",
  67. "metadata": {},
  68. "outputs": [],
  69. "source": [
  70. "msizes = c()\n",
  71. "times_1 = c()\n",
  72. "times_2 = c()\n",
  73. "\n",
  74. "for(i in (1:100) * 10) {\n",
  75. " m <- matrix(rnorm(i^2), i)\n",
  76. " \n",
  77. " times_1 = append(times_1, summary(system.time(sum1(m)))[1])\n",
  78. " times_2 = append(times_2, summary(system.time(sum2(m)))[1])\n",
  79. " msizes = append(msizes, i)\n",
  80. "}\n",
  81. "\n",
  82. "df = data.frame(size=msizes, sum_R = times_1, sum_c = times_2)"
  83. ]
  84. },
  85. {
  86. "cell_type": "code",
  87. "execution_count": null,
  88. "id": "8df4275f",
  89. "metadata": {},
  90. "outputs": [],
  91. "source": []
  92. },
  93. {
  94. "cell_type": "code",
  95. "execution_count": 8,
  96. "id": "3ab35d35",
  97. "metadata": {},
  98. "outputs": [
  99. {
  100. "name": "stderr",
  101. "output_type": "stream",
  102. "text": [
  103. "`geom_smooth()` using method = 'loess' and formula 'y ~ x'\n",
  104. "\n"
  105. ]
  106. },
  107. {
  108. "data": {
  109. "image/png": "iVBORw0KGgoAAAANSUhEUgAAA0gAAANICAIAAAByhViMAAAACXBIWXMAABJ0AAASdAHeZh94\nAAAgAElEQVR4nOzdd2AUdf7/8ZmdLcmmbpJNIZQESAKhSUcRECkq2M7e0fvJeZ6Fs5+n3qno\neXqWU7mznIrlLF8LFkBp0lU8egskJGwIJWXT6ybZ3fn9MUkIAUIguzu7s8/HX+/Jzk7eCxny\n4jPz+Ywoy7IAAACAwKdTuwEAAAB4BsEOAABAIwh2AAAAGkGwAwAA0AiCHQAAgEYQ7AAAADSC\nYAcAAKARBDsAAACN0KvdgIdVVFR08whms9lgMNTU1Ljdbo+05FdMJpMsy01NTWo34nmSJIWH\nhzc1NTU0NKjdi1dERETU1NSo3YVXKCdddXW1JtdL56QLXJx0Z8BisXj2gDhdWgt2Lper+wfR\n6XQul0uTwU4QBFmWPfKn5Id0Op3goZ8BP6T8WKrdhVeIoqjT6dxuNyddYFH+4gROugCk+ZMu\nmHEpFgAAQCMIdgAAABrhq0uxjgMr5r/1xfqcMld06rjLZt9+cXq42MV93BU7v/vgk6Vb9pfL\nUb2GTrl+1pUj47V2BRkAAKD7fDJiJ9dveXfuG5vCps95eu5Dl8Xv+eCZf62vlLu2j/vgt8/N\n/aI4/bqHn/3bo7NG1Hz/3NzPc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iDCZTBUVFW4tLuRtNpvdbrfD4VC7Ec+TJMli\nsTgcjtraWrV78YqYmJjy8nK1u/CKyMhIo9HISRdw9Hp9dHQ0J51v6ATh8sSW4TqH2724uHTd\nunVn/
  110. "text/plain": [
  111. "plot without title"
  112. ]
  113. },
  114. "metadata": {
  115. "image/png": {
  116. "height": 420,
  117. "width": 420
  118. }
  119. },
  120. "output_type": "display_data"
  121. }
  122. ],
  123. "source": [
  124. "ggplot(data=melt(df, id.vars=\"size\"), aes(x=size, y=value)) +\n",
  125. "geom_point(aes(shape=variable)) + geom_smooth(aes(color=variable))"
  126. ]
  127. },
  128. {
  129. "cell_type": "code",
  130. "execution_count": null,
  131. "id": "5fc59dc9",
  132. "metadata": {},
  133. "outputs": [],
  134. "source": []
  135. }
  136. ],
  137. "metadata": {
  138. "kernelspec": {
  139. "display_name": "R",
  140. "language": "R",
  141. "name": "ir"
  142. },
  143. "language_info": {
  144. "codemirror_mode": "r",
  145. "file_extension": ".r",
  146. "mimetype": "text/x-r-source",
  147. "name": "R",
  148. "pygments_lexer": "r",
  149. "version": "4.0.5"
  150. }
  151. },
  152. "nbformat": 4,
  153. "nbformat_minor": 5
  154. }