跳到主要內容

發表文章

JMH 筆記

Nolan Issac 使用 JMH 进行微基准测试:不要猜,要测试! 這幾天讀了幾篇很有趣的文章, 是關於 lambda 跟 jvm 效能評估的文章, 分別是 Java8 Lambda表达式和流操作如何让你的代码变慢5倍 使用JMH进行微基准测试:不要猜,要测试! JMH JMH is a Java harness for building, running, and analysing nano/micro/milli/macro benchmarks written in Java and other languages targetting the JVM. JMH 是用來衡量 JVM 容器上運作的 (Java, Scala, Kotlin, Groovy, Clojure, etc.) 效能的工具, 官方建議透過 maven 來建立測試專案, 可以避免一些奇怪設定影響效能的問題, groupdId 就替換成自己的 package name 吧, artifactId 就替換成測試的 project name, 會按照這個 project name 在當下路徑建立一個資料夾, mvn archetype:generate \ -DinteractiveMode=false \ -DarchetypeGroupId=org.openjdk.jmh \ -DarchetypeArtifactId=jmh-java-benchmark-archetype \ -DgroupId=com.example \ -DartifactId=jmh-benchmark \ -Dversion=1.0 maven Builde 出來的 code import org.openjdk.jmh.annotations.Benchmark; public class MyBenchmark { @Benchmark public void testMethod() { // This is a demo/sample template for building your JMH ben...

[Leetcode] 21. Merge Two Sorted Lists

題目 Merge two sorted linked lists and return it as a new list. The new list should be made by splicing together the nodes of the first two lists. 看完題目, 以為可以用 LinkedList 這類的東西, 想說 ez ... 結果下面給的 hint Sample 根本就不是那麼一回事啊, 抓頭抓抓抓... /** * Definition for singly-linked list. * */ public class ListNode { int val; ListNode next; ListNode(int x) { val = x; } } 先拿到測試資料 /** * Created by jerry on 2017/9/24. * * Merge two sorted linked lists and return it as a new list. * The new list should be made by splicing together the nodes of the first two lists. */ public class LeetCode21MergeTwoSortedListsTest { private LeetCode21MergeTwoSortedLists sol = new LeetCode21MergeTwoSortedLists(); @Test public void test1() { final ListNode l1 = null; final ListNode l2 = new ListNode(0); ListNode act = sol.mergeTwoLists(l1, l2); Assert.assertEquals(0, act.val); } @Test public void test2() { final ListNode l1 = new ListNod...

[Leetcode] 1. TwoSum

建立測試案例 public class LeetCode1TwoSumTest { final LeetCode1TwoSum twoSum = new LeetCode1TwoSum(); /** * Example: * Given nums = [2, 7, 11, 15], target = 9, * Because nums[0] + nums[1] = 2 + 7 = 9, * return [0, 1]. */ @Test public void test1() { final int[] nums = new int[]{2, 7, 11, 15}; final int target = 9; int[] act = twoSum.twoSum(nums, target); Assert.assertTrue(IntStream.of(act).anyMatch(x -> x == 0)); Assert.assertTrue(IntStream.of(act).anyMatch(x -> x == 1)); } @Test public void test2() { final int[] nums = new int[]{3, 3}; final int target = 6; int[] act = twoSum.twoSum(nums, target); Assert.assertTrue(IntStream.of(act).anyMatch(x -> x == 0)); Assert.assertTrue(IntStream.of(act).anyMatch(x -> x == 1)); } @Test public void test3() { final int[] nums = new int[]{3, 2, 4}; final int target = 6; ...

DynamoDB 名詞概念

DynamoDB Download Localhost DynamoDB Table 類似於 RDBMS 的 Table. DynamoDB Table 是一個儲存集合單位。 相當於 MongoDB 的 Collection Items 每個 Table 可以有多個 Items,相當於 RDBMS 的 Rows。 每個 Items 可包含多個 Attributes 相當於 MongoDB 的 Document Attributes: 每個 Items 由一個或多個 Attributes 組成 Attributes 支援最深 32 個層級 Example People Table { "PersonID":"101", "LastName":"Simtih", "FirstName":"Fred", "Phone":"123-456", }, { "PersonID":"102", "LastName":"Jones", "FirstName":"Anytown", "Address":{ "Street":"123 Main", "City":"Anytown", "Zip":123 } } Primary Key Partitiion Key 相當於 RDS 的 Unique Key, 有一組不會重複的 hash value Partition Key + Sort Key (複合鍵) 先找到 unique key 再依照 sort key 做索引, hash + range Hash : select * from xxx where id = hash Hash + range : select * from xxx wh...

GCP Storage 簡介

GCP Storage 簡介 Overview of storage classes 1.Multi-Regional Storage 適合存放經常存取的 "Hot Data" 或者影音串流(streaming videos),有異地備份的功能。 2.Regional Storage 適合存放與 Google Compute Engine Instance 或 Google Cloud DataProc 服務互相配合的資料,在相同的 Regional 可以降低 latency。Google Compute Engine 跟 Google Cloud DataProc 這些 instances 都是拿來處理, 清理, 運算資料用, 要分析的資料適合用這種類型的儲存。存放的費用比 Multi-Regional 還要低一點($0.016 GB/Month)。 3.Nearline Storage 適合存放較低存取的 "Cold Data",比如每月(隔 30 天才會存取一次)需要存取或修改一次的資料,或者適用於一些資料備份(用來回復跟救援的資料),支援整合 AWS Glacier 轉移。 4.Coldline Storage 適合存放較低存取的 "Cold Data",比起 Nearline Storage,Coldline Storage 更適合線上備份跟救援回復的資料(隔 90 天才會存取一次)。 Pricing https://cloud.google.com/storage/pricing Standar Storage 的建議 如果不清楚,資料的存取用途,建議使用 Standard Storage buckets