|
|
- {
- "cells": [
- {
- "cell_type": "code",
- "execution_count": 1,
- "id": "1b48863d",
- "metadata": {},
- "outputs": [],
- "source": [
- "library(ggplot2)\n",
- "library(reshape)"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 2,
- "id": "7e338f77",
- "metadata": {},
- "outputs": [],
- "source": [
- "sum1 <- function(m) {\n",
- " res = 0\n",
- " \n",
- " for(i in 1:dim(m)[1]) {\n",
- " for(j in 1:dim(m)[2]) {\n",
- " res <- res + m[i,j]\n",
- " }\n",
- " }\n",
- "\n",
- " return(res)\n",
- "}\n"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 3,
- "id": "be204fce",
- "metadata": {},
- "outputs": [],
- "source": [
- "sum2 <- function(m) {\n",
- " res = .C(\"sum2\"\n",
- " ,mtrx=as.double(m)\n",
- " ,m=as.integer(dim(m)[1])\n",
- " ,n=as.integer(dim(m)[2])\n",
- " ,res=as.double(0)\n",
- " )\n",
- "\n",
- " return(res$res)\n",
- "}"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 4,
- "id": "b470f59c",
- "metadata": {},
- "outputs": [],
- "source": [
- "dyn.load(\"sum2.so\")"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 7,
- "id": "d8c35f6e",
- "metadata": {},
- "outputs": [],
- "source": [
- "msizes = c()\n",
- "times_1 = c()\n",
- "times_2 = c()\n",
- "\n",
- "for(i in (1:100) * 10) {\n",
- " m <- matrix(rnorm(i^2), i)\n",
- " \n",
- " times_1 = append(times_1, summary(system.time(sum1(m)))[1])\n",
- " times_2 = append(times_2, summary(system.time(sum2(m)))[1])\n",
- " msizes = append(msizes, i)\n",
- "}\n",
- "\n",
- "df = data.frame(size=msizes, sum_R = times_1, sum_c = times_2)"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": null,
- "id": "8df4275f",
- "metadata": {},
- "outputs": [],
- "source": []
- },
- {
- "cell_type": "code",
- "execution_count": 8,
- "id": "3ab35d35",
- "metadata": {},
- "outputs": [
- {
- "name": "stderr",
- "output_type": "stream",
- "text": [
- "`geom_smooth()` using method = 'loess' and formula 'y ~ x'\n",
- "\n"
- ]
- },
- {
- "data": {
- "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/3NzPcp2+6BoAACCw+CLYydW/LF5TP+a2OVeMyRw48pJ7fjdR3Pj9\nOrvclX3kmqxt+01nX33zpMH9+2WOv/a6CZbC7Tvt3OwJAADQkS+uabryc3LdaTcMDlMuvoZk\nnjVA/Dknr0mIN51yH3FM+uA+zctXrd7fb0JPXfGGH7dUJ4wZEHs0j7788str1qxR6qioqPnz\n53ezW2WSV1RUVDeP4590Op0sy6GhoWo34nmiKAqCYDKZDAaD2r14hU6n0+o6Apx0AYqTLnBp\n+6QLcr4Ids6qyjp9VHRY6011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4bqg\nRrADACCA6ZzOGFuOUjtDzVU9U1RtByoj2AEAEKhsNpvlQJ6+qUnZLO2XIet0XIcNZgQ7AAAC\nlizH5WYrpVvSl/VNU7cdqI5gBwBAQLLZbJGFh0w1VcpmRUo/l9HEcF2QI9gBABCorK2LEgui\nWNo/Q9Ve4BcIdgAABKTQirIwe7FSVyf1bIyIYrgOBDsAAAKPzWaz7tvbtmlnlRMIgsCzYgEA\n8E9Wq1Up7Hb78a/qG+qjDuUr9f76hrq4BIbrIDBiBwCAH2pLdR1qhc1mi8vLbluU+Isj9gce\nfNB3zcGPEewAAPB3HbKdzuUM3bVdqcuamteUVa5bt+74/IcgRLADAMC/dB7RbDabJT8vQi8p\nm98VlTa3Dt0BBDsAAPzLCW+qO6rdosQOl3thcem6det80RYCAcEOAAB/1xb1OixKvNxeXuN0\nddgHwYxgBwCA37Hb7W1BrUNiO7rKiSh+U1R6wn0QtFjuBAAAP3V8XAutqgwrbV2UODF5zjM3\nscoJ2mPEDgCAwGCz2eKydwuyrGyWpg9Utx/4IYIdAACB4W+P/ik8P1epG6IstdZEhuvQAcEO\nAIAAcMUVV1yeGGfQtfzitqdnqtsP/BPBDgAAf2e1WkN0upkJccpmWVPz7+e9wXAdjqe1yROx\nsbHdPIIoioIgWCwWT7Tjp8LCwtRuwVtCQkJMJpPaXXiFKIrd//H2T5x0AY2TzjcmTJhwUUJs\n26LE3xSVNrvdZ9xeMJx0QUtrwa6srKybR4iIiDCZTBUVFW4tLuRtNpvdbrfD4VC7Ec+TJMli\nsTgcjtraWrV78YqYmJjy8nK1u/CKyMhIo9HISRdw9Hp9dHQ0J51v6ATh8sSW4TqH2724uHTd\nunVn/
- "text/plain": [
- "plot without title"
- ]
- },
- "metadata": {
- "image/png": {
- "height": 420,
- "width": 420
- }
- },
- "output_type": "display_data"
- }
- ],
- "source": [
- "ggplot(data=melt(df, id.vars=\"size\"), aes(x=size, y=value)) +\n",
- "geom_point(aes(shape=variable)) + geom_smooth(aes(color=variable))"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": null,
- "id": "5fc59dc9",
- "metadata": {},
- "outputs": [],
- "source": []
- }
- ],
- "metadata": {
- "kernelspec": {
- "display_name": "R",
- "language": "R",
- "name": "ir"
- },
- "language_info": {
- "codemirror_mode": "r",
- "file_extension": ".r",
- "mimetype": "text/x-r-source",
- "name": "R",
- "pygments_lexer": "r",
- "version": "4.0.5"
- }
- },
- "nbformat": 4,
- "nbformat_minor": 5
- }
|