SarahCheng
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights
    • Engagement control
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Versions and GitHub Sync Note Insights Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       owned this note    owned this note      
    Published Linked with GitHub
    Subscribed
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    Subscribe
    # 2016q3 Homework1 (phonebook) contributed by <`SarahCheng`> github: https://github.com/SarahYuHanCheng/phonebook.git ### Reviewed by <`snoopy831002`> * 可以在github網站創立好repo之後再clone到本地端會比較方便喔 * 改良之後的cache miss還是太高(74%?) > 好的,謝謝你!再用hash table試試 ## 開發記錄 * 9/24 watch the video, register accounts * 9/25 install lubuntu >> 不需要在內文標注「日期」,HackMD 會追蹤,應該紀錄「主題導向」的實驗和參考資料 [name=jserv] * 9/26 problem: * wifi setting * ~~螢幕畫面截取~~ * ~~linux cmd instruction不熟~~ * problem: * $make 沒有出現"[sudo] password for" * $make plot沒有runtime.png,只有script/runtime.gp >之後有了 * $ lscpu | grep cache沒有反應.. >$ lscpu ~~| grep cache~~即可[time=Tue, Sep 27, 2016 3:37 PM][color=#bdd9f9] * ~~用astyle沒反應~~:因為少了空白 `astyle --style=kr --indent=spaces=4 --indent-switches --suffix=none`空格`*.[ch]` > 需要解釋「沒反應」為何 [name=jserv] * reference: * [linux指令](http://jdev.tw/blog/3599/linux-terminal-commands-and-shortcuts) * [螢幕截取-shutter](https://blog.gtwang.org/linux/linux-screenshot-program-shutter/) * [makefile裡GCC](http://www.cmlab.csie.ntu.edu.tw/~daniel/linux/gcc.html) * [TempoJiJi](https://hackmd.io/MYUwzMCGCckAwFoBMcAmB2BAWa1UMmCIRAEYkA2MddEADjmCyA==?view)同學的開發記錄 * [ruby0109](https://github.com/ruby0109/phonebook/blob/master/phonebook_hash.c)同學的開發記錄 * [c14006078](https://hackmd.io/MYNgnCDsCsYEwFoAmInQQFngMwQQwCM5dI88BmAU3LnIEYlsAGIA#)同學的開發記錄 ## 開發環境 * CPU: Intel(R) Core(TM) i7-3520M cpu @ 2.90GHz * MEM: 125GB * Cache: * L1d cache: 32K * L1i cache: 32K * L2 cache: 256K * L3 cache: 4096K 使用 `lscpu` 和 `sudo lshw` 可看到硬體資訊 ## 修改結構大小降低cache miss steps: 1.修改`phonebook_opt.h`如下圖 ```clike= typedef struct __PHONE_BOOK_DETAILS { char firstName[16]; char email[16]; char phone[10]; char cell[10]; char addr1[16]; char addr2[16]; char city[16]; char state[2]; char zip[5]; } Details; typedef struct __PHONE_BOOK_ENTRY { char lastName[MAX_LAST_NAME_SIZE]; struct __PHONE_BOOK_ENTRY *pNext; Details *details; } entry; ``` 2.`phonebook_opt.c`的append()和findName()複製orig版本 3.記得解開 the comment ` #define OPT 1` 4.清空cache: ```shell $echo 1 | sudo tee /proc/sys/vm/drop_caches ``` 5.make plot 即得下列資訊 ``` size of entry : 128 bytes execution time of append() : 0.087335 sec execution time of findName() : 0.005850 sec Performance counter stats for './phonebook_orig' (100 runs): 1,426,148 cache-misses # 82.108 % of all cache refs ( +- 0.48% ) (74.11%) 1,736,927 cache-references ( +- 0.54% ) (74.39%) 305,721,382 instructions # 1.47 insns per cycle ( +- 0.18% ) (77.20%) 207,828,652 cycles ( +- 0.24% ) (76.70%) 0.068671339 seconds time elapsed ( +- 1.91% ) ``` ![](https://i.imgur.com/9EpJOU5.png) ``` size of entry : 24 bytes execution time of append() : 0.036632 sec execution time of findName() : 0.002973 sec Performance counter stats for './phonebook_opt' (100 runs): 232,097 cache-misses # 74.079 % of all cache refs ( +- 0.37% ) (74.46%) 313,312 cache-references ( +- 0.51% ) (74.79%) 278,824,752 instructions # 1.75 insns per cycle ( +- 0.28% ) (76.75%) 159,089,222 cycles ( +- 0.28% ) (77.42%) 0.050675378 seconds time elapsed ( +- 1.75% ) ``` ![](https://i.imgur.com/9WR7hCG.png) ![](https://i.imgur.com/ja5Skgj.png) ``` Performance counter stats for './phonebook_orig' (100 runs): 1,469,675 cache-misses # 81.589 % of all cache refs ( +- 0.61% ) 1,801,320 cache-references ( +- 0.60% ) 310,382,365 instructions # 1.45 insns per cycle ( +- 0.01% ) 214,099,227 cycles ( +- 0.17% ) 0.070388042 seconds time elapsed ( +- 2.18% ) ``` ``` 235,670 cache-misses # 79.971 % of all cache refs ( +- 0.22% ) 294,695 cache-references ( +- 0.21% ) 288,137,012 instructions # 1.78 insns per cycle ( +- 0.00% ) 162,238,829 cycles ( +- 0.08% ) ``` ## fgets ###### Use fgets characteristic to delay the replacing '\n' with '\0'. 利用 fgets的特性,man 完就會發現它會在讀到 newline 或是 EOF停下來並且在他們後面會多種一個 '\0',接著的 code 就是把 newline 變成 '\0',我們延後替換 newline,我操作只比較前面的長度,真的找到了再把 newline 換掉即可。 * main.c ```= while (fgets(line, sizeof(line), fp)) e = append(line, e); ``` * phonebook_opt.c ```= /* because the assert test, we can’t modify the strcut*/ if (strncasecmp(lastname, pHead->lastName, len) == 0 && (pHead->lastName[len] == ’\n’ || pHead->lastName[len] == ’\0’)) { pHead->lastName[len] = ’\0’; return pHead; ``` 原本的程式是將字典直接建好,這邊我們先建檢索,等到findName找到時我們再去補上他的資料,這樣也能減少 append()。 * Q1:`error: stray ‘342’ in program` > A:ascii characters missing,程式碼用複製貼上,導致'\n'的引號格式不符 * Q2:Assertion failed,還不知道怎解決 ``` size of entry : 24 bytes phonebook_opt: main.c:89: main: Assertion `0 == strcmp(findName(input, e)->lastName, "zyxel")' failed. ./phonebook_opt: 已經終止 ``` ![](https://i.imgur.com/9GJangy.png) 6.用`astyle --style=kr --indent=spaces=4 --indent-switches --suffix=none *.[ch]` 7.`ln -sf ../../scripts/pre-commit.hook .git/hooks/pre-commit` ## Hash 不明原因 ```= error: conflicting types for ‘hashAppend’ int *hashAppend(char *lastName, hashTable *ht) ``` [無解,也許是編譯警告太多了](http://www.wnqzw.com/article/9823.html) ## GIT step: 1.[指令參考](http://fireqqtw.logdown.com/posts/196392-git-casually-notes#reset) 2.[本機與github同步](http://wiki.csie.ncku.edu.tw/github) > 貼id_rsa.pub所有內容到github上key的設定 2.若出現`fatal: Not a git repository (or any of the parent directories): .git`,因為還沒有.git目錄,要先`git init` 3. ``` fatal: The current branch master has no upstream branch. To push the current branch and set the remote as upstream, use git push --set-upstream phonebook master ``` ###### tags: `sarah`,`phonebook`

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully