Skip to main content

Posts

Perl Float Matrix Multiplication

Floating point performance compared to integer multiplication on Perl This is much the same as Perl Integer performance, and disappointly inferior to Javascript. Not a whole lot worse, comparable, really, but MY language should be better than the OTHER language! :-)

Perl Matrix Multiplication

Here's the Perl script for matrix multiplication. It's derived from the RosettaCode site with slight modifications ... I didn't like some things about their way of doing things, but it's much the same in the end. #! /usr/bin/perl5.20.2 use 5.020; use warnings; use strict; use English; use Time::HiRes qw(gettimeofday tv_interval); use autodie; use Data::Dumper; # ------------------------------------------------------- # SUBROUTINES # # ⋯ ⋯ ⋯ ⋯ ⋯ ⋯ ⋯ ⋯ ⋯ ⋯ ⋯ ⋯ ⋯ ⋯ ⋯ ⋯ ⋯ ⋯ ⋯ ⋯ ⋯ ⋯ ⋯ ⋯ ⋯ ⋯ ⋯ ⋯ # matmult - multiple matrices. Copied from # RosettaCode.orgwiki/Matrix_multiplication#Perl. # sub matmult { my ( $M, $N ) = @_; my ( $rows, $cols ) = (scalar @$M, scalar @{$N->[0]} ); my $prod = []; my $k = @$N - 1; for my $i ( 0..$rows - 1 ) { for my $j ( 0 .. $cols - 1 ) { $prod->[$i][$j] += $M->[$i][$_] * $N->[$_][$j] for 0..$k; } } return $prod; } # ⋯ ⋯ ⋯

Node JS Multiplying Float Matrices

I don't know why I wrote such stupid code for readMatrix.js . I guess when someone uses a new language their brain cells seize up, effective function becomes impossible. After tests I ran on Friday, I wanted to see how Javascript does with floating point numbers? JS only supports 64 bit floating-point numbers, but there must be special code in their to make integers look like integers ... unless their isn't. When I went to update my code to support numbers with fractions, my first thought was to flag whether a decimal point had been seen and then keep track of the value by which to divide, multiplying by ten for each fractional digit. I quickly realized I was sinking into the mire of coding stupidity; JS must have a function to convert strings into integers or floats, and indeed it has parseInt() and parseFloat() . But in my research I discovered ( or re-discovered ) that there's no need for the conversion. Like Perl, JS allows arithmetic on the string representation

Node JS As The Universal Shell Scripting System

For the past 20 years, I've focused on programming in real languages for real applications, as opposed to web stuff, :-). When I have dealt with the web, it's been using server-side scripts. Definitely not that Javascript crud. Mind you, back when I worked for a porn website, they also came up with a JS based website, Simple.com, long before other people were doing all-JS interfaces. But the time has come to re-evaluate ... well, everything. Javascript can be checked for validity and style using JSHint & JSLint; it can be debugged. There are frameworks and layers that make it possible to do useful things easily, treating old JS as a sort of widely-supported low-level language on which to implement more elegant systems. One of these new paradigms is the implementation of node.js to run JS programs on the server, rather than in a web page. Node uses the Google's V8 Javascript engine from the Chrome browser, which means a large corporation ensures high performance on

Saint Patrick's Day plus one