Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
---
title: Deploy TypeScript on Google Cloud C4A (Arm-based Axion VMs)

minutes_to_complete: 30

who_is_this_for: This learning path is intended for software developers deploying and optimizing TypeScript workloads on Linux/Arm64 environments, specifically using Google Cloud C4A virtual machines powered by Axion processors.

learning_objectives:
- Provision an Arm-based SUSE SLES virtual machine on Google Cloud (C4A with Axion processors)
- Install TypeScript on a SUSE Arm64 (C4A) instance
- Validate TypeScript functionality by creating, compiling, and running a simple TypeScript script on the Arm64 VM
- Benchmark TypeScript performance using a JMH-style custom benchmark with perf_hooks on Arm64 (Aarch64) architecture

prerequisites:
- A [Google Cloud Platform (GCP)](https://cloud.google.com/free) account with billing enabled
- Basic familiarity with [TypeScript](https://www.typescriptlang.org/) and Node.js runtime environment


author: Pareena Verma

##### Tags
skilllevels: Introductory
subjects: Web
cloud_service_providers: Google Cloud

armips:
- Neoverse

tools_software_languages:
- TypeScript
- node.js
- npm
- perf_hooks

operatingsystems:
- Linux

# ================================================================================
# FIXED, DO NOT MODIFY
# ================================================================================
further_reading:
- resource:
title: Google Cloud documentation
link: https://cloud.google.com/docs
type: documentation

- resource:
title: TypeScript documentation
link: https://www.typescriptlang.org/docs/
type: documentation

- resource:
title: TypeScript Benchmark documentation
link: https://tech.spiko.io/posts/benchmarking-typescript-type-checking/
type: documentation

weight: 1
layout: "learningpathall"
learning_path_main_page: "yes"
---
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
# ================================================================================
# FIXED, DO NOT MODIFY THIS FILE
# ================================================================================
weight: 21 # Set to always be larger than the content in this path to be at the end of the navigation.
title: "Next Steps" # Always the same, html page title.
layout: "learningpathall" # All files under learning paths have this same wrapper for Hugo processing.
---
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
---
title: Getting started with TypeScript on Google Axion C4A (Arm Neoverse-V2)

weight: 2

layout: "learningpathall"
---

## Google Axion C4A Arm instances in Google Cloud

Google Axion C4A is a family of Arm-based virtual machines built on Google’s custom Axion CPU, which is based on Arm Neoverse-V2 cores. Designed for high-performance and energy-efficient computing, these virtual machines offer strong performance for modern cloud workloads such as CI/CD pipelines, microservices, media processing, and general-purpose applications.

The C4A series provides a cost-effective alternative to x86 virtual machines while leveraging the scalability and performance benefits of the Arm architecture in Google Cloud.

To learn more about Google Axion, refer to the [Introducing Google Axion Processors, our new Arm-based CPUs](https://cloud.google.com/blog/products/compute/introducing-googles-new-arm-based-cpu) blog.

## TypeScript

TypeScript is an open-source, strongly typed programming language developed and maintained by Microsoft.

It is a superset of JavaScript, which means all valid JavaScript code is also valid TypeScript, but TypeScript adds **static typing, interfaces, and advanced tooling** to help developers write more reliable and maintainable code.

TypeScript is widely used for **web applications, server-side development (Node.js), and large-scale JavaScript projects** where type safety and code quality are important. Learn more from the [TypeScript official website](https://www.typescriptlang.org/) and its [handbook and documentation](https://www.typescriptlang.org/docs/).
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
---
title: TypeScript Baseline Testing on Google Axion C4A Arm Virtual Machine
weight: 5

### FIXED, DO NOT MODIFY
layout: learningpathall
---

## Baseline Setup for TypeScript
This guide covers the **baseline setup and testing** of TypeScript on a **Google Axion C4A virtual machine** running SUSE Linux. The objective is to ensure that the TypeScript environment is installed correctly, that basic compilation works, and that a simple TypeScript script can run on the VM.

### Set Up a TypeScript Project
Before testing, we need a project folder with all necessary TypeScript dependencies.

**1. Create project folder**

Create a dedicated folder for your TypeScript project:

```console
mkdir ~/typescript-benchmark
cd ~/typescript-benchmark
```
This ensures all files are organized in one place, separate from system files.

**2. Initialize npm project**

Initialize a Node.js project with default settings:

```console
npm init -y
```
The above command creates a `package.json` file, which manages your project dependencies and scripts.

**3. Install Node.js type definitions**

These definitions allow TypeScript to understand Node.js APIs, enabling type checking and code autocompletion.

```console
npm install --save-dev @types/node
```

You should see output similar to:
```output
{
"name": "typescript-benchmark",
"version": "1.0.0",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"description": ""
}
```

### Baseline Testing
After setting up the project, we perform baseline testing to verify that TypeScript is working correctly on the GCP SUSE VM.

**1. Create a Simple TypeScript File**

Create a file named `hello.ts` with the following content:

```typescript
const greet = (name: string): string => {
return `Hello, ${name}!`;
};

console.log(greet("GCP SUSE ARM64"));
```
This simple function demonstrates TypeScript syntax, type annotations, and basic console output.

**2. Compile TypeScript**

The TypeScript compiler (`tsc`) converts `hello.ts` into `hello.js`, which can be executed by Node.js.

```console
tsc hello.ts
```

**3. Run compiled JavaScript**

After compiling the TypeScript file into JavaScript (`hello.js`), you need to execute it using `Node.js`. This step verifies that:

- The TypeScript code was successfully compiled into valid JavaScript.
- The JavaScript code runs correctly in the Node.js runtime on your GCP SUSE VM.

Execute the compiled JavaScript file:

```console
node hello.js
```

You should see output similar to:
```output
Hello, GCP SUSE ARM64
```
This verifies the basic functionality of the TypeScript installation before proceeding to the benchmarking.
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
---
title: TypeScript Benchmarking
weight: 6

### FIXED, DO NOT MODIFY
layout: learningpathall
---


## JMH-style Custom Benchmarking

This section demonstrates how to **benchmark TypeScript functions** using a JMH-style approach with Node.js `perf_hooks`. Unlike simple `console.time` timing, this method performs **repeated iterations**, calculates the **average execution time**, and provides more **reliable and stable performance measurements** on your Arm64 SUSE VM.

### Create the Benchmark Script
Create a file named `benchmark_jmh.ts` in your project folder:

```typescript
import { performance } from 'perf_hooks';

// Function to benchmark
const sumArray = (n: number) => {
let sum = 0;
for (let i = 0; i < n; i++) sum += i;
return sum;
};

// Benchmark parameters
const iterations = 10; // Number of repeated runs
const arraySize = 1_000_000; // Size of array
let totalTime = 0;

// JMH-style repeated runs
for (let i = 0; i < iterations; i++) {
const start = performance.now();
sumArray(arraySize);
const end = performance.now();
const timeTaken = end - start;
totalTime += timeTaken;
console.log(`Iteration ${i + 1}: ${timeTaken.toFixed(3)} ms`);
}

// Compute average execution time
const averageTime = totalTime / iterations;
console.log(`\nAverage execution time over ${iterations} iterations: ${averageTime.toFixed(3)} ms`);
```

- **`performance.now()`** → Provides a high-resolution timestamp in milliseconds for precise timing measurements.
- **`sumArray`** → A sample CPU-bound function that sums numbers from 0 to `n`.
- **`iterations`** → Defines how many times the benchmark should run to stabilize results and minimize random variations.
- **`for` loop** → Executes the target function multiple times and records the duration of each run.
- **`totalTime / iterations`** → Calculates the **average execution time** across all runs, similar to how **JMH (Java Microbenchmark Harness)** operates in Java.

This JMH-style benchmarking approach provides **more accurate and repeatable performance metrics** than a single execution, making it ideal for performance testing on Arm-based systems.

### Compile the TypeScript Benchmark
Compile the TypeScript benchmark file into JavaScript:

```console
tsc benchmark_jmh.ts
```
This generates a `benchmark_jmh.js` file that can be executed by Node.js.

### Run the Benchmark
Execute the compiled JavaScript file:

```console
node benchmark_jmh.js
```
You should see an output similar to:

```output
Iteration 1: 2.286 ms
Iteration 2: 0.749 ms
Iteration 3: 1.145 ms
Iteration 4: 0.674 ms
Iteration 5: 0.671 ms
Iteration 6: 0.671 ms
Iteration 7: 0.672 ms
Iteration 8: 0.667 ms
Iteration 9: 0.667 ms
Iteration 10: 0.673 ms

Average execution time over 10 iterations: 0.888 ms
```

### Benchmark Metrics Explained

- **Iteration times** → Each iteration shows the **time taken for a single execution** of the function being benchmarked.
- **Average execution time** → Calculated as the sum of all iteration times divided by the number of iterations. This provides a **stable measure of typical performance**.
- **Why multiple iterations?**
- Single-run timing can be inconsistent due to factors such as CPU scheduling, memory allocation, or caching.
- Repeating the benchmark multiple times and averaging reduces variability and gives **more reliable performance results**, similar to Java’s JMH benchmarking approach.
**Interpretation:**
- The average execution time reflects how efficient the function is under normal conditions.
- Initial iterations may take longer due to **initialization overhead**, which is common in Node.js performance tests.

### Benchmark summary on x86_64
To compare the benchmark results, the following results were collected by running the same benchmark on a `x86 - c4-standard-4` (4 vCPUs, 15 GB Memory) x86_64 VM in GCP, running SUSE:

| Iteration | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | Average |
|-----------|-------|-------|-------|-------|-------|-------|-------|-------|-------|-------|---------|
| Time (ms) | 3.217 | 0.631 | 0.632 | 0.611 | 0.612 | 0.614 | 0.614 | 0.611 | 0.606 | 0.532 | 0.868 |

### Benchmark summary on Arm64
Results from the earlier run on the `c4a-standard-4` (4 vCPU, 16 GB memory) Arm64 VM in GCP (SUSE):

| Iteration | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | Average |
|-----------|-------|-------|-------|-------|-------|-------|-------|-------|-------|-------|---------|
| Time (ms) | 2.286 | 0.749 | 1.145 | 0.674 | 0.671 | 0.671 | 0.672 | 0.667 | 0.667 | 0.673 | 0.888 |

### TypeScript performance benchmarking comparison on Arm64 and x86_64

When you compare the benchmarking results, you will notice that on the Google Axion C4A Arm-based instances:

- The average execution time on Arm64 (~0.888 ms) shows that CPU-bound TypeScript operations run efficiently on Arm-based VMs.
- Initial iterations may show slightly higher times due to runtime warm-up and optimization overhead, which is common across architectures.
- Arm64 demonstrates stable iteration times after the first run, indicating consistent performance for repeated workloads.
- Compared to typical x86_64 VMs, Arm64 performance is comparable for lightweight TypeScript computations, with potential advantages in power efficiency and cost for cloud deployments.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
---
title: Install TypeScript
weight: 4

### FIXED, DO NOT MODIFY
layout: learningpathall
---

## Install TypeScript on GCP VM
This page guides you through installing **TypeScript** and its prerequisites on a **GCP SUSE Arm64 VM**. We will install Node.js, npm, TypeScript, and ts-node, and verify that everything works correctly.

### Update SUSE System
Before installing new packages, refresh the repositories and update existing packages:

```console
sudo zypper refresh
sudo zypper update -y
```
This ensures that your VM has the latest package information and security updates.

### Install Node.js and npm
Node.js is required to run TypeScript scripts, and npm is the Node.js package manager:

```console
sudo zypper install -y nodejs npm
```
The above command installs Node.js runtime and npm on your GCP SUSE VM.

### Install TypeScript globally
TypeScript (`tsc`) compiles `.ts` files to JavaScript, and ts-node allows you to run TypeScript directly without compiling:

```console
sudo npm install -g typescript ts-node
```
- Installing globally (`-g`) makes `tsc` and `ts-node` available in any directory on your VM.

### Verify installations
Check that Node.js, npm, TypeScript, and ts-node are installed correctly:

```console
node -v
npm -v
tsc -v
ts-node -v
```

**Output:**

```output
>node -v
v18.20.5
>npm -v
10.8.2
>tsc -v
Version 5.9.3
> ts-node -v
v10.9.2
```

These version outputs confirm that the Node.js and TypeScript are installed correctly and are ready for development or benchmarking.
Loading